@@ -186,11 +186,18 @@ AttachedFunctionBuilderRequest::evaluate(Evaluator &evaluator,
186
186
// / Attempt to infer the function builder type for a declaration.
187
187
static Type inferFunctionBuilderType (ValueDecl *decl) {
188
188
auto dc = decl->getDeclContext ();
189
- if (!dc->isTypeContext ())
189
+ if (!dc->isTypeContext () || isa<ProtocolDecl>(dc) )
190
190
return Type ();
191
191
192
192
auto funcDecl = dyn_cast<FuncDecl>(decl);
193
- if (!funcDecl)
193
+ if (!funcDecl || !funcDecl->hasBody () ||
194
+ !decl->getDeclContext ()->getParentSourceFile ())
195
+ return Type ();
196
+
197
+ // Check whether there are any return statements in the function's body.
198
+ // If there are, the function builder transform will be disabled,
199
+ // so don't infer a function builder.
200
+ if (!TypeChecker::findReturnStatements (funcDecl).empty ())
194
201
return Type ();
195
202
196
203
// Only getters can have function builders. When we find one, look at
@@ -248,12 +255,6 @@ static Type inferFunctionBuilderType(ValueDecl *decl) {
248
255
if (matches.size () == 0 )
249
256
return Type ();
250
257
251
- // Check whether there are any return statements in the function's body.
252
- // If there are, the function builder transform will be disabled,
253
- // so don't infer a function builder.
254
- if (!TypeChecker::findReturnStatements (funcDecl).empty ())
255
- return Type ();
256
-
257
258
// Determine whether there is more than one actual function builder type.
258
259
Type functionBuilderType = matches[0 ].functionBuilderType ;
259
260
for (const auto &match : matches) {
0 commit comments