7
7
// Type check testing
8
8
// 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
9
9
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
+
10
15
// Check diagnostic buffer names
11
16
// 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
12
17
// RUN: %FileCheck -check-prefix DIAG_BUFFERS %s < %t.diags
16
21
// RUN: %target-codesign %t/main
17
22
// RUN: %target-run %t/main | %FileCheck %s
18
23
19
- // Test unqualified lookup from within a macro expansion
24
+ #if IMPORT_MACRO_LIBRARY
25
+ import freestanding_macro_library
26
+ #else
20
27
@freestanding ( declaration, names: named ( StructWithUnqualifiedLookup) )
21
28
macro 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
22
38
23
39
let world = 3 // to be used by the macro expansion below
24
40
@@ -29,9 +45,6 @@ func lookupGlobalFreestandingExpansion() {
29
45
print ( StructWithUnqualifiedLookup ( ) . foo ( ) )
30
46
}
31
47
32
- @freestanding ( declaration)
33
- macro anonymousTypes( public: Bool = false , _: ( ) -> String ) = #externalMacro( module: " MacroDefinition " , type: " DefineAnonymousTypesMacro " )
34
-
35
48
#anonymousTypes( public: true ) { " hello " }
36
49
37
50
// CHECK-SIL: sil @$s9MacroUser03$s9A71User33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf0_4namefMu_C5helloSSyF
@@ -43,9 +56,6 @@ struct Main {
43
56
}
44
57
}
45
58
46
- @freestanding ( declaration)
47
- macro freestandingWithClosure< T> ( _ value: T , body: ( T ) -> T ) = #externalMacro( module: " MacroDefinition " , type: " EmptyDeclarationMacro " )
48
-
49
59
// Unqualified lookup for names defined within macro arguments.
50
60
#freestandingWithClosure( 0 ) { x in x }
51
61
@@ -61,15 +71,11 @@ struct HasInnerClosure {
61
71
62
72
// Arbitrary names at global scope
63
73
64
- @freestanding ( declaration, names: arbitrary) macro bitwidthNumberedStructs( _ baseName: String ) = #externalMacro( module: " MacroDefinition " , type: " DefineBitwidthNumberedStructsMacro " )
65
-
66
74
#bitwidthNumberedStructs( " MyIntGlobal " )
67
75
68
76
func testArbitraryAtGlobal( ) {
69
77
_ = MyIntGlobal16 ( )
70
78
}
71
79
72
- @freestanding ( expression) macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " MacroDefinition " , type: " StringifyMacro " )
73
-
74
80
// DIAG_BUFFERS: @__swiftmacro_9MacroUser33_{{.*}}9stringifyfMf1_{{.*}}warning: 'deprecated()' is deprecated
75
81
// DIAG_BUFFERS: @__swiftmacro_9MacroUser33_{{.*}}9stringifyfMf2_{{.*}}warning: 'deprecated()' is deprecated
0 commit comments