|
39 | 39 | // RUN: %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/nested.swift |
40 | 40 | // RUN: %diff %t/nested.swift %t/nested.swift.expected |
41 | 41 |
|
| 42 | +// RUN: not %target-swift-frontend-verify -I %t -plugin-path %swift-plugin-dir -typecheck %t/unparsed.swift 2>%t/output.txt -Rmacro-expansions |
| 43 | +// RUN: not %update-verify-tests < %t/output.txt | %FileCheck --check-prefix CHECK-UNPARSED %s |
| 44 | + |
| 45 | +// RUN: not %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/escaped.swift 2>%t/output.txt -Rmacro-expansions |
| 46 | +// RUN: %update-verify-tests < %t/output.txt |
| 47 | +// RUN: %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/escaped.swift -Rmacro-expansions |
| 48 | +// RUN: %diff %t/escaped.swift %t/escaped.swift.expected |
| 49 | + |
42 | 50 | //--- single.swift |
43 | 51 | @attached(peer, names: overloaded) |
44 | 52 | macro unstringifyPeer(_ s: String) = |
@@ -129,9 +137,9 @@ func foo(_ x: Int) { |
129 | 137 | } |
130 | 138 | """) |
131 | 139 | //expected-expansion@+5:14{{ |
132 | | - // expected-error@3 {{cannot find 'b' in scope; did you mean 'x'?}} |
133 | 140 | // expected-note@1 2{{'x' declared here}} |
134 | 141 | // expected-error@2 {{cannot find 'a' in scope; did you mean 'x'?}} |
| 142 | + // expected-error@3 {{cannot find 'b' in scope; did you mean 'x'?}} |
135 | 143 | //}} |
136 | 144 | func foo() {} |
137 | 145 |
|
@@ -238,3 +246,62 @@ func bar(_ y: Int) { |
238 | 246 | // }} |
239 | 247 | func bar() {} |
240 | 248 |
|
| 249 | +//--- unparsed.h |
| 250 | +// CHECK-UNPARSED: no files updated: found diagnostics in unparsed files TMP_DIR{{/|\\}}unparsed.h |
| 251 | +void foo(int len, int *p) __attribute__((swift_attr("@_SwiftifyImport(.countedBy(pointer: .param(2), count: \"len\"))"))); |
| 252 | + |
| 253 | +//--- module.modulemap |
| 254 | +module UnparsedClang { |
| 255 | + header "unparsed.h" |
| 256 | + export * |
| 257 | +} |
| 258 | + |
| 259 | +//--- unparsed.swift |
| 260 | +import UnparsedClang |
| 261 | + |
| 262 | +func bar() { |
| 263 | + let a: CInt = 1 |
| 264 | + var b: CInt = 13 |
| 265 | + foo(a, &b) |
| 266 | +} |
| 267 | + |
| 268 | +//--- escaped.swift |
| 269 | +@attached(peer, names: overloaded) |
| 270 | +macro unstringifyPeer(_ s: String) = |
| 271 | + #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") |
| 272 | + |
| 273 | +@unstringifyPeer(""" |
| 274 | +func foo(_ x: Int) { |
| 275 | + let a = "\\(x)" |
| 276 | + let b = "\\(x)" |
| 277 | +} |
| 278 | +""") |
| 279 | +// NB: DiagnosticVerifier interprets "\\(x)" as "\(x)" |
| 280 | +// expected-expansion@+3:30{{ |
| 281 | +// expected-remark@2{{macro content: |let a = "\\(x)"|}} |
| 282 | +// }} |
| 283 | +func foo() { let _ = "\(2)" } |
| 284 | + |
| 285 | +//--- escaped.swift.expected |
| 286 | +@attached(peer, names: overloaded) |
| 287 | +macro unstringifyPeer(_ s: String) = |
| 288 | + #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") |
| 289 | + |
| 290 | +// expected-note@+1 6{{in expansion of macro 'unstringifyPeer' on global function 'foo()' here}} |
| 291 | +@unstringifyPeer(""" |
| 292 | +func foo(_ x: Int) { |
| 293 | + let a = "\\(x)" |
| 294 | + let b = "\\(x)" |
| 295 | +} |
| 296 | +""") |
| 297 | +// NB: DiagnosticVerifier interprets "\\(x)" as "\(x)" |
| 298 | +// expected-expansion@+8:30{{ |
| 299 | +// expected-remark@1{{macro content: |func foo(_ x: Int) {|}} |
| 300 | +// expected-warning@2{{initialization of immutable value 'a' was never used; consider replacing with assignment to '_' or removing it}} |
| 301 | +// expected-remark@2{{macro content: | let a = "\\(x)"|}} |
| 302 | +// expected-warning@3{{initialization of immutable value 'b' was never used; consider replacing with assignment to '_' or removing it}} |
| 303 | +// expected-remark@3{{macro content: | let b = "\\(x)"|}} |
| 304 | +// expected-remark@4{{macro content: |}|}} |
| 305 | +// }} |
| 306 | +func foo() { let _ = "\(2)" } |
| 307 | + |
0 commit comments