77// Type check testing
88// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-experimental-feature FreestandingMacros -parse-as-library -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -swift-version 5 %S/Inputs/top_level_freestanding_other.swift
99
10+ // Type check testing with imported macro declarations
11+ // RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/freestanding_macro_library.swiftmodule %S/Inputs/freestanding_macro_library.swift -module-name freestanding_macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
12+
13+ // RUN: %target-typecheck-verify-swift -swift-version 5 -enable-experimental-feature FreestandingMacros -parse-as-library -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -DIMPORT_MACRO_LIBRARY -swift-version 5 %S/Inputs/top_level_freestanding_other.swift -I %t
14+
1015// Check diagnostic buffer names
1116// RUN: %target-swift-frontend -typecheck -swift-version 5 -enable-experimental-feature FreestandingMacros -parse-as-library -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -swift-version 5 %s %S/Inputs/top_level_freestanding_other.swift 2> %t.diags
1217// RUN: %FileCheck -check-prefix DIAG_BUFFERS %s < %t.diags
1621// RUN: %target-codesign %t/main
1722// RUN: %target-run %t/main | %FileCheck %s
1823
19- // Test unqualified lookup from within a macro expansion
24+ #if IMPORT_MACRO_LIBRARY
25+ import freestanding_macro_library
26+ #else
2027@freestanding ( declaration, names: named ( StructWithUnqualifiedLookup) )
2128macro structWithUnqualifiedLookup( ) = #externalMacro( module: " MacroDefinition " , type: " DefineStructWithUnqualifiedLookupMacro " )
29+ @freestanding ( declaration)
30+ macro anonymousTypes( public: Bool = false , _: ( ) -> String ) = #externalMacro( module: " MacroDefinition " , type: " DefineAnonymousTypesMacro " )
31+ @freestanding ( declaration)
32+ macro freestandingWithClosure< T> ( _ value: T , body: ( T ) -> T ) = #externalMacro( module: " MacroDefinition " , type: " EmptyDeclarationMacro " )
33+ @freestanding ( declaration, names: arbitrary) macro bitwidthNumberedStructs( _ baseName: String ) = #externalMacro( module: " MacroDefinition " , type: " DefineBitwidthNumberedStructsMacro " )
34+ @freestanding ( expression) macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " MacroDefinition " , type: " StringifyMacro " )
35+ #endif
36+
37+ // Test unqualified lookup from within a macro expansion
2238
2339let world = 3 // to be used by the macro expansion below
2440
@@ -29,9 +45,6 @@ func lookupGlobalFreestandingExpansion() {
2945 print ( StructWithUnqualifiedLookup ( ) . foo ( ) )
3046}
3147
32- @freestanding ( declaration)
33- macro anonymousTypes( public: Bool = false , _: ( ) -> String ) = #externalMacro( module: " MacroDefinition " , type: " DefineAnonymousTypesMacro " )
34-
3548#anonymousTypes( public: true ) { " hello " }
3649
3750// CHECK-SIL: sil @$s9MacroUser03$s9A71User33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf0_4namefMu_C5helloSSyF
@@ -43,9 +56,6 @@ struct Main {
4356 }
4457}
4558
46- @freestanding ( declaration)
47- macro freestandingWithClosure< T> ( _ value: T , body: ( T ) -> T ) = #externalMacro( module: " MacroDefinition " , type: " EmptyDeclarationMacro " )
48-
4959// Unqualified lookup for names defined within macro arguments.
5060#freestandingWithClosure( 0 ) { x in x }
5161
@@ -61,15 +71,11 @@ struct HasInnerClosure {
6171
6272// Arbitrary names at global scope
6373
64- @freestanding ( declaration, names: arbitrary) macro bitwidthNumberedStructs( _ baseName: String ) = #externalMacro( module: " MacroDefinition " , type: " DefineBitwidthNumberedStructsMacro " )
65-
6674#bitwidthNumberedStructs( " MyIntGlobal " )
6775
6876func testArbitraryAtGlobal( ) {
6977 _ = MyIntGlobal16 ( )
7078}
7179
72- @freestanding ( expression) macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " MacroDefinition " , type: " StringifyMacro " )
73-
7480// DIAG_BUFFERS: @__swiftmacro_9MacroUser33_{{.*}}9stringifyfMf1_{{.*}}warning: 'deprecated()' is deprecated
7581// DIAG_BUFFERS: @__swiftmacro_9MacroUser33_{{.*}}9stringifyfMf2_{{.*}}warning: 'deprecated()' is deprecated
0 commit comments