6
6
// Diagnostics testing
7
7
// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS
8
8
9
+ // Diagnostics testing by importing macros from a module
10
+ // 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)
11
+ // RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/freestanding_macro_library_2.swiftmodule %S/Inputs/freestanding_macro_library_2.swift -module-name freestanding_macro_library_2 -load-plugin-library %t/%target-library-name(MacroDefinition) -I %t
12
+
13
+ // RUN: %target-typecheck-verify-swift -swift-version 5 -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -I %t -DIMPORT_MACRO_LIBRARY
14
+
9
15
// RUN: not %target-swift-frontend -swift-version 5 -typecheck -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -serialize-diagnostics-path %t/macro_expand.dia %s -emit-macro-expansion-files no-diagnostics > %t/macro-printing.txt
10
16
// RUN: c-index-test -read-diagnostics %t/macro_expand.dia 2>&1 | %FileCheck -check-prefix CHECK-DIAGS %s
11
17
28
34
29
35
// CHECK-MODULE-TRACE: {{libMacroDefinition.dylib|libMacroDefinition.so|MacroDefinition.dll}}
30
36
37
+ #if IMPORT_MACRO_LIBRARY
38
+ import freestanding_macro_library
39
+ import freestanding_macro_library_2
40
+ #else
41
+ @freestanding ( declaration, names: named ( StructWithUnqualifiedLookup) )
42
+ macro structWithUnqualifiedLookup( ) = #externalMacro( module: " MacroDefinition " , type: " DefineStructWithUnqualifiedLookupMacro " )
43
+
44
+ @freestanding ( declaration)
45
+ macro anonymousTypes( _: ( ) -> String ) = #externalMacro( module: " MacroDefinition " , type: " DefineAnonymousTypesMacro " )
46
+
47
+ @freestanding ( declaration)
48
+ macro freestandingWithClosure< T> ( _ value: T , body: ( T ) -> T ) = #externalMacro( module: " MacroDefinition " , type: " EmptyDeclarationMacro " )
49
+
50
+ @freestanding ( declaration, names: arbitrary) macro bitwidthNumberedStructs( _ baseName: String ) = #externalMacro( module: " MacroDefinition " , type: " DefineBitwidthNumberedStructsMacro " )
51
+
52
+ @freestanding ( expression) macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " MacroDefinition " , type: " StringifyMacro " )
53
+
54
+ @freestanding ( declaration, names: arbitrary) macro bitwidthNumberedStructs( _ baseName: String , blah: Bool ) = #externalMacro( module: " MacroDefinition " , type: " DefineBitwidthNumberedStructsMacro " )
55
+ #endif
56
+
31
57
#if TEST_DIAGNOSTICS
32
58
@freestanding ( declaration)
33
59
macro NotCovered( ) = #externalMacro( module: " MacroDefinition " , type: " InvalidMacro " )
@@ -93,7 +119,6 @@ struct Bad {}
93
119
#endif
94
120
95
121
@freestanding ( expression) macro customFileID( ) -> String = #externalMacro( module: " MacroDefinition " , type: " FileIDMacro " )
96
- @freestanding ( expression) macro stringify< T> ( _ value: T ) -> ( T , String ) = #externalMacro( module: " MacroDefinition " , type: " StringifyMacro " )
97
122
@freestanding ( expression) macro fileID< T: ExpressibleByStringLiteral > ( ) -> T = #externalMacro( module: " MacroDefinition " , type: " FileIDMacro " )
98
123
@freestanding ( expression) macro recurse( _: Bool ) = #externalMacro( module: " MacroDefinition " , type: " RecursiveMacro " )
99
124
@freestanding ( expression) macro assert( _: Bool ) = #externalMacro( module: " MacroDefinition " , type: " AssertMacro " )
@@ -267,9 +292,6 @@ func testNestedDeclInExpr() {
267
292
let _: ( ) -> Void = #nestedDeclInExpr
268
293
}
269
294
270
- @freestanding( declaration, names: arbitrary) macro bitwidthNumberedStructs( _ baseName: String) = #externalMacro( module: " MacroDefinition " , type: " DefineBitwidthNumberedStructsMacro " )
271
- // Test overload
272
- @freestanding ( declaration, names: arbitrary) macro bitwidthNumberedStructs( _ baseName: String, blah: Bool) = #externalMacro( module: " MacroDefinition " , type: " DefineBitwidthNumberedStructsMacro " )
273
295
// Test non-arbitrary names
274
296
@freestanding( declaration, names: named ( A) , named ( B) , named ( foo) , named ( addOne) )
275
297
macro defineDeclsWithKnownNames( ) = #externalMacro( module: " MacroDefinition " , type: " DefineDeclsWithKnownNamesMacro " )
@@ -288,12 +310,6 @@ let blah = false
288
310
#endif
289
311
290
312
// Test unqualified lookup from within a macro expansion
291
- @freestanding ( declaration, names: named ( StructWithUnqualifiedLookup) )
292
- macro struct WithUnqualifiedLookup ( ) = #externalMacro( module: " MacroDefinition " , type: " DefineStructWithUnqualifiedLookupMacro " )
293
-
294
- @freestanding ( declaration)
295
- macro anonymousTypes( _: ( ) - > String) = #externalMacro(module: " MacroDefinition" , type: " DefineAnonymousTypesMacro " )
296
-
297
313
// FIXME: Global freestanding macros not yet supported in script mode.
298
314
#if false
299
315
let world = 3 // to be used by the macro expansion below
@@ -376,9 +392,6 @@ struct ContainerOfNumberedStructs {
376
392
}
377
393
378
394
// Avoid re-type-checking declaration macro arguments.
379
- @freestanding ( declaration)
380
- macro freestandingWithClosure< T> ( _ value: T , body: ( T ) -> T ) = #externalMacro( module: " MacroDefinition " , type: " EmptyDeclarationMacro " )
381
-
382
395
func testFreestandingWithClosure( i: Int) {
383
396
#freestandingWithClosure( i) { x in x }
384
397
0 commit comments