Skip to content

Commit 6eaa503

Browse files
committed
Diagnose CustomAttrs as needed in @abi (macro tests)
Additional tests for the previous commit “Diagnose CustomAttrs as needed in `@abi`”.
1 parent 196f787 commit 6eaa503

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/Macros/macro_expand_peers.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
// REQUIRES: swift_swift_parser, executable_test
2+
// REQUIRES: swift_feature_ABIAttribute
23

34
// For _Concurrency.
45
// UNSUPPORTED: use_os_stdlib
56
// UNSUPPORTED: back_deployment_runtime
67

78
// RUN: %empty-directory(%t)
89
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -parse-as-library -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
9-
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -parse-as-library -disable-availability-checking -DTEST_DIAGNOSTICS
10+
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -parse-as-library -disable-availability-checking -enable-experimental-feature ABIAttribute -DTEST_DIAGNOSTICS
1011

1112
// Check with the imported macro library vs. the local declaration of the macro.
1213
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/macro_library.swiftmodule %S/Inputs/macro_library.swift -module-name macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
1314

14-
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -parse-as-library -disable-availability-checking -DIMPORT_MACRO_LIBRARY -I %t -DTEST_DIAGNOSTICS
15+
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -parse-as-library -disable-availability-checking -DIMPORT_MACRO_LIBRARY -I %t -enable-experimental-feature ABIAttribute -DTEST_DIAGNOSTICS
1516

1617

1718
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) -parse-as-library %s -disable-availability-checking -dump-macro-expansions > %t/expansions-dump.txt 2>&1
@@ -309,3 +310,26 @@ func closuresInPeerMacroCrash() {}
309310
@trait(Trait {})
310311
@trait(Trait {})
311312
var closuresInPeerMacroOnVariableCrash: Int = 0
313+
314+
// Test that macros can't be used in @abi
315+
316+
#if swift(>=5.3) && TEST_DIAGNOSTICS
317+
struct ABIAttrWithAttachedMacro {
318+
// expected-error@+1 {{macro 'addCompletionHandler()' cannot be expanded in '@abi' attribute}}
319+
@abi(@addCompletionHandler func fn1() async)
320+
@addCompletionHandler func fn1() async {}
321+
// From diagnostics in the expansion:
322+
// expected-note@-2 3{{in expansion of macro 'addCompletionHandler' on instance method 'fn1()' here}}
323+
// expected-note@-4 {{'fn1()' previously declared here}}
324+
325+
// expected-error@+1 {{macro 'addCompletionHandler()' cannot be expanded in '@abi' attribute}}
326+
@abi(@addCompletionHandler func fn2() async)
327+
func fn2() async {}
328+
329+
@abi(func fn3() async)
330+
@addCompletionHandler func fn3() async {}
331+
// From diagnostics in the expansion:
332+
// expected-note@-2 2{{in expansion of macro 'addCompletionHandler' on instance method 'fn3()' here}}
333+
// expected-note@-4 {{'fn3()' previously declared here}}
334+
}
335+
#endif

0 commit comments

Comments
 (0)