Skip to content

Commit 292e3a0

Browse files
committed
[Macros] Add more tests for macro arguments.
1 parent bf5aad6 commit 292e3a0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/Macros/attached_macros_diags.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@
77
@attached(accessor) macro m2(_: Int) -> Void = #externalMacro(module: "MyMacros", type: "Macro2")
88
// expected-warning@-1{{external macro implementation type 'MyMacros.Macro2' could not be found for macro 'm2'}}
99
// expected-note@-2{{candidate has partially matching parameter list (Int)}}
10+
// expected-note@-3{{candidate expects value of type 'Int' for parameter #1 (got 'String')}}
1011

1112
@attached(accessor) macro m2(_: Double) -> Void = #externalMacro(module: "MyMacros", type: "Macro2")
1213
// expected-warning@-1{{external macro implementation type 'MyMacros.Macro2' could not be found for macro 'm2'}}
1314
// expected-note@-2{{candidate has partially matching parameter list (Double)}}
15+
// expected-note@-3{{candidate expects value of type 'Double' for parameter #1 (got 'String')}}
16+
17+
@attached(accessor) macro m3(message: String) -> Void = #externalMacro(module: "MyMacros", type: "Macro3")
18+
// expected-warning@-1{{external macro implementation type 'MyMacros.Macro3' could not be found for macro 'm3(message:)'}}
19+
20+
@expression macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MyMacros", type: "StringifyMacro")
21+
// expected-warning@-1{{external macro implementation type 'MyMacros.StringifyMacro' could not be found for macro 'stringify'}}
22+
// expected-note@-2{{'stringify' declared here}}
1423

1524
@m1 struct X1 { }
1625

@@ -29,3 +38,29 @@ struct SkipNestedType {
2938
@m1 var x: Int = 0
3039
// expected-error@-1{{external macro implementation type 'MyMacros.Macro1' could not be found for macro 'm1()'; the type must be public and provided via '-load-plugin-library'}}
3140
}
41+
42+
struct TestMacroArgs {
43+
@m1("extra arg") struct Args1 {} // expected-error{{argument passed to call that takes no arguments}}
44+
45+
@m2(10) struct Args2 {}
46+
47+
@m2(10.0) struct Args3 {}
48+
49+
@m2("") struct Args4 {} // expected-error{{no exact matches in call to macro 'm2'}}
50+
51+
@m2(Nested.x) struct Args5 {}
52+
53+
struct Nested {
54+
static let x = 10
55+
56+
@m2(x) struct Args1 {}
57+
58+
@m2(Nested.x) struct Args2 {}
59+
}
60+
61+
@m3(message: stringify(Nested.x).1) struct Args6 {}
62+
// expected-error@-1{{expansion of macro 'stringify' requires leading '#'}}
63+
64+
@m3(message: #stringify(Nested.x).1) struct Args7 {}
65+
// expected-error@-1{{external macro implementation type 'MyMacros.StringifyMacro' could not be found for macro 'stringify'}}
66+
}

0 commit comments

Comments
 (0)