File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -1952,11 +1952,13 @@ unsigned AbstractClosureExpr::getDiscriminator() const {
19521952 // If we don't have a discriminator, and either
19531953 // 1. We have ill-formed code and we're able to assign a discriminator, or
19541954 // 2. We are in a macro expansion buffer
1955+ // 3. We are within top-level code where there's nothing to anchor to
19551956 //
19561957 // then assign the next discriminator now.
19571958 if (getRawDiscriminator () == InvalidDiscriminator &&
19581959 (ctx.Diags .hadAnyError () ||
1959- getParentSourceFile ()->getFulfilledMacroRole () != std::nullopt )) {
1960+ getParentSourceFile ()->getFulfilledMacroRole () != std::nullopt ||
1961+ getParent ()->isModuleScopeContext ())) {
19601962 auto discriminator = ctx.getNextDiscriminator (getParent ());
19611963 ctx.setMaxAssignedDiscriminator (getParent (), discriminator + 1 );
19621964 const_cast <AbstractClosureExpr *>(this )->
Original file line number Diff line number Diff line change 1+ // REQUIRES: swift_swift_parser, executable_test
2+
3+ // RUN: %empty-directory(%t)
4+ // RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift
5+
6+ // RUN: %target-swift-frontend -typecheck -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -parse-as-library -emit-reference-dependencies-path %t/MacroUser.swiftdeps -primary-file %s
7+
8+ // Note: this test ensures that we don't crash when trying to mangle a symbol
9+ // within a closure passed to a macro.
10+
11+ @freestanding ( declaration)
12+ macro Empty< T> ( _ x: T ) = #externalMacro( module: " MacroDefinition " , type: " EmptyDeclarationMacro " )
13+
14+ #Empty {
15+ struct S {
16+ static var foo : Int { 0 }
17+ }
18+ _ = S . foo
19+ }
You can’t perform that action at this time.
0 commit comments