Skip to content

Commit 73cb75a

Browse files
authored
Merge pull request #85526 from hnrklssn/improve-uvt
Improve uvt
2 parents f1f55bb + 3373903 commit 73cb75a

File tree

2 files changed

+178
-33
lines changed

2 files changed

+178
-33
lines changed

test/Utils/update-verify-tests/expansion.swift

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
// RUN: %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/nested.swift
4040
// RUN: %diff %t/nested.swift %t/nested.swift.expected
4141

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+
4250
//--- single.swift
4351
@attached(peer, names: overloaded)
4452
macro unstringifyPeer(_ s: String) =
@@ -129,9 +137,9 @@ func foo(_ x: Int) {
129137
}
130138
""")
131139
//expected-expansion@+5:14{{
132-
// expected-error@3 {{cannot find 'b' in scope; did you mean 'x'?}}
133140
// expected-note@1 2{{'x' declared here}}
134141
// 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'?}}
135143
//}}
136144
func foo() {}
137145

@@ -238,3 +246,62 @@ func bar(_ y: Int) {
238246
// }}
239247
func bar() {}
240248

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

Comments
 (0)