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 @@ -1934,11 +1934,13 @@ unsigned AbstractClosureExpr::getDiscriminator() const {
1934
1934
// If we don't have a discriminator, and either
1935
1935
// 1. We have ill-formed code and we're able to assign a discriminator, or
1936
1936
// 2. We are in a macro expansion buffer
1937
+ // 3. We are within top-level code where there's nothing to anchor to
1937
1938
//
1938
1939
// then assign the next discriminator now.
1939
1940
if (getRawDiscriminator () == InvalidDiscriminator &&
1940
1941
(ctx.Diags .hadAnyError () ||
1941
- getParentSourceFile ()->getFulfilledMacroRole () != std::nullopt)) {
1942
+ getParentSourceFile ()->getFulfilledMacroRole () != std::nullopt ||
1943
+ getParent ()->isModuleScopeContext ())) {
1942
1944
auto discriminator = ctx.getNextDiscriminator (getParent ());
1943
1945
ctx.setMaxAssignedDiscriminator (getParent (), discriminator + 1 );
1944
1946
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