@@ -2235,23 +2235,26 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
22352235 TypeChecker &TC;
22362236 AbstractFunctionDecl *Implementation;
22372237 OpaqueTypeDecl *OpaqueDecl;
2238+ BraceStmt *Body;
22382239 SmallVector<std::pair<Expr*, Type>, 4 > Candidates;
22392240
22402241 bool HasInvalidReturn = false ;
22412242
22422243public:
22432244 OpaqueUnderlyingTypeChecker (TypeChecker &TC,
22442245 AbstractFunctionDecl *Implementation,
2245- OpaqueTypeDecl *OpaqueDecl)
2246+ OpaqueTypeDecl *OpaqueDecl,
2247+ BraceStmt *Body)
22462248 : TC(TC),
22472249 Implementation (Implementation),
2248- OpaqueDecl(OpaqueDecl)
2250+ OpaqueDecl(OpaqueDecl),
2251+ Body(Body)
22492252 {
22502253
22512254 }
22522255
22532256 void check () {
2254- Implementation-> getBody () ->walk (*this );
2257+ Body ->walk (*this );
22552258
22562259 // If given function has any invalid returns in the body
22572260 // let's not try to validate the types, since it wouldn't
@@ -2835,26 +2838,27 @@ performTopLevelDeclDiagnostics(TypeChecker &TC, TopLevelCodeDecl *TLCD) {
28352838
28362839// / Perform diagnostics for func/init/deinit declarations.
28372840void swift::performAbstractFuncDeclDiagnostics (TypeChecker &TC,
2838- AbstractFunctionDecl *AFD) {
2839- assert (AFD->getBody () && " Need a body to check" );
2841+ AbstractFunctionDecl *AFD,
2842+ BraceStmt *body) {
2843+ assert (body && " Need a body to check" );
28402844
28412845 // Don't produce these diagnostics for implicitly generated code.
28422846 if (AFD->getLoc ().isInvalid () || AFD->isImplicit () || AFD->isInvalid ())
28432847 return ;
28442848
28452849 // Check for unused variables, as well as variables that are could be
28462850 // declared as constants.
2847- AFD-> getBody () ->walk (VarDeclUsageChecker (TC, AFD));
2851+ body ->walk (VarDeclUsageChecker (TC, AFD));
28482852
28492853 // If the function has an opaque return type, check the return expressions
28502854 // to determine the underlying type.
28512855 if (auto opaqueResultTy = AFD->getOpaqueResultTypeDecl ()) {
2852- OpaqueUnderlyingTypeChecker (TC, AFD, opaqueResultTy).check ();
2856+ OpaqueUnderlyingTypeChecker (TC, AFD, opaqueResultTy, body ).check ();
28532857 } else if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
28542858 if (accessor->isGetter ()) {
28552859 if (auto opaqueResultTy
28562860 = accessor->getStorage ()->getOpaqueResultTypeDecl ()) {
2857- OpaqueUnderlyingTypeChecker (TC, AFD, opaqueResultTy).check ();
2861+ OpaqueUnderlyingTypeChecker (TC, AFD, opaqueResultTy, body ).check ();
28582862 }
28592863 }
28602864 }
0 commit comments