66// Diagnostics testing
77// 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
88
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+
915// 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
1016// RUN: c-index-test -read-diagnostics %t/macro_expand.dia 2>&1 | %FileCheck -check-prefix CHECK-DIAGS %s
1117
2834
2935// CHECK-MODULE-TRACE: {{libMacroDefinition.dylib|libMacroDefinition.so|MacroDefinition.dll}}
3036
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+
3157#if TEST_DIAGNOSTICS
3258@freestanding ( declaration)
3359macro NotCovered( ) = #externalMacro( module: " MacroDefinition " , type: " InvalidMacro " )
@@ -93,7 +119,6 @@ struct Bad {}
93119#endif
94120
95121@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 " )
97122@freestanding ( expression) macro fileID< T: ExpressibleByStringLiteral > ( ) -> T = #externalMacro( module: " MacroDefinition " , type: " FileIDMacro " )
98123@freestanding ( expression) macro recurse( _: Bool ) = #externalMacro( module: " MacroDefinition " , type: " RecursiveMacro " )
99124@freestanding ( expression) macro assert( _: Bool ) = #externalMacro( module: " MacroDefinition " , type: " AssertMacro " )
@@ -267,9 +292,6 @@ func testNestedDeclInExpr() {
267292 let _: ( ) -> Void = #nestedDeclInExpr
268293}
269294
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 " )
273295// Test non-arbitrary names
274296@freestanding( declaration, names: named ( A) , named ( B) , named ( foo) , named ( addOne) )
275297macro defineDeclsWithKnownNames( ) = #externalMacro( module: " MacroDefinition " , type: " DefineDeclsWithKnownNamesMacro " )
@@ -288,12 +310,6 @@ let blah = false
288310#endif
289311
290312// 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-
297313// FIXME: Global freestanding macros not yet supported in script mode.
298314#if false
299315let world = 3 // to be used by the macro expansion below
@@ -376,9 +392,6 @@ struct ContainerOfNumberedStructs {
376392}
377393
378394// 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-
382395func testFreestandingWithClosure( i: Int) {
383396 #freestandingWithClosure( i) { x in x }
384397
0 commit comments