- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathattached_macros_diags.swift
96 lines (63 loc) · 4.02 KB
/
attached_macros_diags.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// REQUIRES: swift_swift_parser
// RUN: %empty-directory(%t)
// 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
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -disable-availability-checking -module-name MacrosTest
@attached(peer) macro m1()= #externalMacro(module:"MacroDefinition", type:"EmptyPeerMacro")
@attached(peer) macro m2(_:Int)= #externalMacro(module:"MacroDefinition", type:"EmptyPeerMacro")
// expected-note@-1{{'m2' declared here}}
// expected-note@-2{{candidate expects value of type 'Int' for parameter #1 (got 'String')}}
@attached(peer) macro m2(_:Double)= #externalMacro(module:"MacroDefinition", type:"EmptyPeerMacro")
// expected-note@-1{{candidate expects value of type 'Double' for parameter #1 (got 'String')}}
@attached(peer) macro m3(message:String)= #externalMacro(module:"MacroDefinition", type:"EmptyPeerMacro")
// expected-note@-1{{'m3(message:)' declared here}}
@attached(peer) macro m4(_ param1:Int, label2 param2:String)= #externalMacro(module:"MacroDefinition", type:"EmptyPeerMacro")
// expected-note@-1 3 {{'m4(_:label2:)' declared here}}
@attached(peer) macro m5(label1:Int, label2:String)= #externalMacro(module:"MacroDefinition", type:"EmptyPeerMacro")
// expected-note@-1{{'m5(label1:label2:)' declared here}}
@attached(peer) macro m6(label:Int=42)= #externalMacro(module:"MacroDefinition", type:"EmptyPeerMacro")
@freestanding(expression) macro stringify<T>(_ value:T)->(T,String)= #externalMacro(module:"MyMacros", type:"StringifyMacro")
// expected-warning@-1{{external macro implementation type 'MyMacros.StringifyMacro' could not be found for macro 'stringify'}}
// expected-note@-2{{'stringify' declared here}}
@m1structX1{}
@m2structX2{} // expected-error{{missing argument for parameter #1 in macro expansion}}{{4-4=(<#Int#>)}}
@m3structX3{} // expected-error{{missing argument for parameter 'message' in macro expansion}}{{4-4=(message: <#String#>)}}
@m4structX4{} // expected-error{{missing arguments for parameters #1, 'label2' in macro expansion}}{{4-4=(<#Int#>, label2: <#String#>)}}
@m5structX5{} // expected-error{{missing arguments for parameters 'label1', 'label2' in macro expansion}}{{4-4=(label1: <#Int#>, label2: <#String#>)}}
@m6structX6{}
// Check for nesting rules.
structSkipNestedType{
@propertyWrapper
structm1<T>{
init(){}
varwrappedValue:T
}
// We select the macro, not the property wrapper.
@m1varx:Int=0
//expected-note@-1{{did you mean 'x'?}}
func test(){
let _:m1<Int>= _x
// expected-error@-1{{cannot find '_x' in scope}}
}
}
structTestMacroArgs{
@m1("extra arg")structArgs1{} // expected-error{{argument passed to macro expansion that takes no arguments}}
@m2(10)structArgs2{}
@m2(10.0)structArgs3{}
@m2("")structArgs4{} // expected-error{{no exact matches in call to macro 'm2'}}
@m2(Nested.x)structArgs5{}
@m4(10)structArgs6{} // expected-error{{missing argument for parameter 'label2' in macro expansion}}{{9-9=, label2: <#String#>}}
@m4(label2:"test")structArgs7{} // expected-error{{missing argument for parameter #1 in macro expansion}}{{7-7=<#Int#>, }}
structNested{
staticletx=10
@m2(x)structArgs1{}
@m2(Nested.x)structArgs2{}
}
@m3(message:stringify(Nested.x).1)structArgs8{}
// expected-error@-1{{expansion of macro 'stringify' requires leading '#'}}
@m3(message: #stringify().1)structArgs9{}
// expected-error@-1{{missing argument for parameter #1 in macro expansion}}
@m3(message: #stringify(Nested.x).1)structArgs10{}
// Allow macros to have arbitrary generic specialization lists, but warn
// https://github.com/swiftlang/swift/issues/75500
@m1<UInt>structArgs11{} // expected-warning {{cannot specialize a non-generic external macro 'm1()'}}
}