@@ -234,11 +234,6 @@ checkSupportedWithSectionAttribute(const Expr *expr,
234234 }
235235 continue ;
236236 }
237-
238- // No auto-closures
239- if (isa<AbstractClosureExpr>(expr)) {
240- return std::make_pair (expr, Default);
241- }
242237
243238 // Function conversions are allowed if the conversion is to '@convention(c)'
244239 if (auto functionConvExpr = dyn_cast<FunctionConversionExpr>(expr)) {
@@ -270,6 +265,60 @@ checkSupportedWithSectionAttribute(const Expr *expr,
270265 return std::make_pair (expr, OpaqueDeclRef);
271266 }
272267
268+ // Allow specific patterns of AutoClosureExpr, which is used in static func
269+ // references. E.g. "MyStruct.staticFunc" is:
270+ // - autoclosure_expr type="() -> ()"
271+ // - call_expr type="()"
272+ // - dot_syntax_call_expr
273+ // - declref_expr decl="MyStruct.staticFunc"
274+ // - dot_self_expr type="MyStruct.Type"
275+ // - type_expr type="MyStruct.Type"
276+ if (auto autoClosureExpr = dyn_cast<AutoClosureExpr>(expr)) {
277+ auto subExpr = autoClosureExpr->getUnwrappedCurryThunkExpr ();
278+ if (auto dotSyntaxCall = dyn_cast<DotSyntaxCallExpr>(subExpr)) {
279+ if (auto declRef = dyn_cast<DeclRefExpr>(dotSyntaxCall->getFn ())) {
280+ if (auto funcDecl = dyn_cast<FuncDecl>(declRef->getDecl ())) {
281+ // Check if it's a function on a concrete non-generic type
282+ if (!funcDecl->hasGenericParamList () &&
283+ !funcDecl->getDeclContext ()->isGenericContext () &&
284+ funcDecl->isStatic ()) {
285+ if (auto args = dotSyntaxCall->getArgs ()) {
286+ if (args->size () == 1 ) {
287+ // Check that the single arg is a DotSelfExpr with only a
288+ // direct concrete TypeExpr inside
289+ if (auto dotSelfExpr =
290+ dyn_cast<DotSelfExpr>(args->get (0 ).getExpr ())) {
291+ if (const TypeExpr *typeExpr =
292+ dyn_cast<TypeExpr>(dotSelfExpr->getSubExpr ())) {
293+ auto baseType = typeExpr->getType ();
294+ if (baseType && baseType->is <MetatypeType>()) {
295+ auto instanceType =
296+ baseType->getMetatypeInstanceType ();
297+ if (auto nominal =
298+ instanceType
299+ ->getNominalOrBoundGenericNominal ()) {
300+ if (!nominal->hasGenericParamList () &&
301+ !nominal->getDeclContext ()->isGenericContext () &&
302+ !nominal->isResilient ()) {
303+ continue ;
304+ }
305+ }
306+ }
307+ }
308+ }
309+ }
310+ }
311+ }
312+ }
313+ }
314+ }
315+ return std::make_pair (expr, Default);
316+ }
317+
318+ // Other closure expressions (auto-closures) are not allowed
319+ if (isa<AbstractClosureExpr>(expr))
320+ return std::make_pair (expr, Default);
321+
273322 // DotSelfExpr for metatype references (but only a direct TypeExpr inside)
274323 if (const DotSelfExpr *dotSelfExpr = dyn_cast<DotSelfExpr>(expr)) {
275324 if (const TypeExpr *typeExpr =
0 commit comments