|
2 | 2 |
|
3 | 3 | @expression macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
|
4 | 4 | // expected-note@-1 2{{'stringify' declared here}}
|
| 5 | +// expected-warning@-2{{external macro implementation type}} |
5 | 6 | @expression macro missingMacro1(_: Any) = MissingModule.MissingType // expected-note{{'missingMacro1' declared here}}
|
6 | 7 | // expected-warning@-1{{external macro definitions are now written using #externalMacro}}{{43-68=#externalMacro(module: "MissingModule", type: "MissingType")}}
|
7 |
| -@expression macro missingMacro2(_: Any) = MissingModule.MissingType |
| 8 | +// expected-warning@-2{{external macro implementation type}} |
| 9 | +@expression macro missingMacro2(_: Any) = #externalMacro(module: "MissingModule", type: "MissingType") |
| 10 | +// expected-warning@-1{{external macro implementation type}} |
8 | 11 |
|
9 | 12 | protocol P { }
|
10 | 13 |
|
11 |
| -@expression macro tryToHide<T: P>(_: P) -> some P = BuiltinMacros.Blah |
| 14 | +@expression macro tryToHide<T: P>(_: T) -> some P = #externalMacro(module: "BuiltinMacros", type: "Blah") |
12 | 15 | // expected-error@-1{{some' types are only permitted in properties, subscripts, and functions}}
|
| 16 | +// expected-error@-2{{generic parameter 'T' could not be inferred}} |
13 | 17 |
|
14 | 18 | internal struct X { } // expected-note{{type declared here}}
|
15 | 19 |
|
16 |
| -@expression public macro createAnX: X = BuiltinMacros.Blah |
| 20 | +@expression public macro createAnX: X = #externalMacro(module: "BuiltinMacros", type: "Blah") |
17 | 21 | // expected-error@-1{{macro cannot be declared public because its result type uses an internal type}}
|
| 22 | +// expected-warning@-2{{external macro implementation type}} |
18 | 23 |
|
19 |
| -@expression macro m1: Int = A.B |
20 |
| -@expression macro m1: Float = A.B |
| 24 | +@expression macro m1: Int = #externalMacro(module: "BuiltinMacros", type: "Blah") |
| 25 | +// expected-warning@-1{{external macro implementation type}} |
| 26 | +@expression macro m1: Float = #externalMacro(module: "BuiltinMacros", type: "Blah") |
| 27 | +// expected-warning@-1{{external macro implementation type}} |
21 | 28 |
|
22 |
| -@expression macro m2: Int = A.B // expected-note{{'m2' previously declared here}} |
23 |
| -@expression macro m2: Int = A.B // expected-error{{invalid redeclaration of 'm2'}} |
| 29 | +@expression macro m2: Int = #externalMacro(module: "BuiltinMacros", type: "Blah") // expected-note{{'m2' previously declared here}} |
| 30 | +// expected-warning@-1{{external macro implementation type}} |
| 31 | +@expression macro m2: Int = #externalMacro(module: "BuiltinMacros", type: "Blah") // expected-error{{invalid redeclaration of 'm2'}} |
| 32 | +// expected-warning@-1{{external macro implementation type}} |
24 | 33 |
|
25 |
| -@expression macro m3(_: Int) -> Int = A.B |
26 |
| -@expression macro m3(_: Int) -> Float = A.B |
| 34 | +@expression macro m3(_: Int) -> Int = #externalMacro(module: "BuiltinMacros", type: "Blah") |
| 35 | +// expected-warning@-1{{external macro implementation type}} |
| 36 | +@expression macro m3(_: Int) -> Float = #externalMacro(module: "BuiltinMacros", type: "Blah") |
| 37 | +// expected-warning@-1{{external macro implementation type}} |
27 | 38 |
|
28 |
| -@expression macro m4(_: Int) -> Int = A.B // expected-note{{'m4' previously declared here}} |
29 |
| -@expression macro m4(_: Int) -> Int = A.B // expected-error{{invalid redeclaration of 'm4'}} |
| 39 | +@expression macro m4(_: Int) -> Int = #externalMacro(module: "BuiltinMacros", type: "Blah") // expected-note{{'m4' previously declared here}} |
| 40 | +// expected-warning@-1{{external macro implementation type}} |
| 41 | +@expression macro m4(_: Int) -> Int = #externalMacro(module: "BuiltinMacros", type: "Blah") // expected-error{{invalid redeclaration of 'm4'}} |
| 42 | +// expected-warning@-1{{external macro implementation type}} |
30 | 43 |
|
31 | 44 | struct ZZZ {
|
32 |
| - macro m5: Int = A.B |
| 45 | + macro m5: Int = #externalMacro(module: "BuiltinMacros", type: "Blah") |
33 | 46 | // expected-error@-1{{macro 'm5' can only be declared at file scope}}
|
34 | 47 | // expected-error@-2{{macro 'm5' must declare its applicable contexts (e.g., '@expression')}}
|
| 48 | + // expected-warning@-3{{external macro implementation type}} |
35 | 49 | }
|
36 | 50 |
|
37 |
| -@expression macro multiArgMacro(_: Any, second: Any) = MissingModule.MissingType |
| 51 | +@expression macro multiArgMacro(_: Any, second: Any) = #externalMacro(module: "MissingModule", type: "MissingType") |
38 | 52 | // expected-note@-1{{'multiArgMacro(_:second:)' declared here}}
|
| 53 | +// expected-warning@-2{{external macro implementation type}} |
| 54 | + |
| 55 | +@expression macro overloaded1(_ p: P) = #externalMacro(module: "MissingModule", type: "MissingType") |
| 56 | +// expected-warning@-1{{external macro implementation type}} |
39 | 57 |
|
40 |
| -@expression macro overloaded1(_ p: P) = MissingModule.MissingType |
41 | 58 | func overloaded1(_ p: Any) { }
|
42 | 59 |
|
43 |
| -@expression macro notOverloaded1(_ p: P) = MissingModule.MissingType // expected-note{{'notOverloaded1' previously declared here}} |
44 |
| -@expression macro notOverloaded1(_ p: P) = MissingModule.MissingOtherType // expected-error{{invalid redeclaration of 'notOverloaded1'}} |
| 60 | +@expression macro notOverloaded1(_ p: P) = #externalMacro(module: "MissingModule", type: "MissingType") // expected-note{{'notOverloaded1' previously declared here}} |
| 61 | +// expected-warning@-1{{external macro implementation type}} |
| 62 | +@expression macro notOverloaded1(_ p: P) = #externalMacro(module: "MissingModule", type: "MissingOtherType") // expected-error{{invalid redeclaration of 'notOverloaded1'}} |
| 63 | +// expected-warning@-1{{external macro implementation type}} |
45 | 64 |
|
46 |
| -@expression macro intIdentity(value: Int, _: Float) -> Int = MissingModule.MissingType |
| 65 | +@expression macro intIdentity(value: Int, _: Float) -> Int = #externalMacro(module: "MissingModule", type: "MissingType") |
47 | 66 | // expected-note@-1{{macro 'intIdentity(value:_:)' declared here}}
|
| 67 | +// expected-warning@-2{{external macro implementation type}} |
48 | 68 |
|
49 | 69 | func testDiags(a: Int, b: Int) {
|
50 | 70 | // FIXME: Bad diagnostic.
|
@@ -79,3 +99,10 @@ func shadow(a: Int, b: Int, stringify: Int) {
|
79 | 99 | func testMissing() {
|
80 | 100 | #missingMacro1("hello") // expected-error{{external macro implementation type 'MissingModule.MissingType' could not be found for macro 'missingMacro1'; the type must be public and provided via '-load-plugin-library'}}
|
81 | 101 | }
|
| 102 | + |
| 103 | +@expression macro undefined() // expected-error{{macro 'undefined()' requires a definition}} |
| 104 | + |
| 105 | +func testExternalMacroOutOfPlace() { |
| 106 | + let _: Int = #externalMacro(module: "A", type: "B") |
| 107 | + // expected-error@-1{{macro 'externalMacro' can only be used to define another macro}} |
| 108 | +} |
0 commit comments