Skip to content

Commit 075e7d4

Browse files
committed
[Function builders] Separate out the Fix-It tests.
Testing newlines in Fix-Its does not work well with Windows, so separate out the Fix-It tests for function builder stubs.
1 parent 3b8656d commit 075e7d4

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

test/Constraints/function_builder_diags.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ struct TupleBuilder { // expected-note 2 {{struct 'TupleBuilder' declared here}}
4646

4747
@_functionBuilder
4848
struct TupleBuilderWithoutIf { // expected-note 3{{struct 'TupleBuilderWithoutIf' declared here}}
49-
// expected-note@-1{{add 'buildOptional(_:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'if' statements without an 'else'}}{{31-31=\n static func buildOptional(_ component: <#Component#>?) -> <#Component#> {\n <#code#>\n \}}}
50-
// expected-note@-2{{add 'buildEither(first:)' and 'buildEither(second:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'if'-'else' and 'switch'}}{{31-31=\n static func buildEither(first component: <#Component#>) -> <#Component#> {\n <#code#>\n \}\n\n static func buildEither(second component: <#Component#>) -> <#Component#> {\n <#code#>\n \}}}
51-
// expected-note@-3{{add 'buildArray(_:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'for'..'in' loops}}{{31-31=\n static func buildArray(_ components: [<#Component#>]) -> <#Component#> {\n <#code#>\n \}}}
49+
// expected-note@-1{{add 'buildOptional(_:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'if' statements without an 'else'}}
50+
// expected-note@-2{{add 'buildEither(first:)' and 'buildEither(second:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'if'-'else' and 'switch'}}
51+
// expected-note@-3{{add 'buildArray(_:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'for'..'in' loops}}
5252
static func buildBlock() -> () { }
5353

5454
static func buildBlock<T1>(_ t1: T1) -> T1 {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking
2+
// UNSUPPORTED: windows
3+
// Line-feeds in Fix-Its fail to check on Windows.
4+
5+
@_functionBuilder
6+
struct Maker {} // expected-error {{function builder must provide at least one static 'buildBlock' method}}{{15-15=\n static func buildBlock(_ components: <#Component#>...) -> <#Component#> {\n <#code#>\n \}}}
7+
8+
@_functionBuilder
9+
struct TupleBuilderWithoutIf { // expected-note 3{{struct 'TupleBuilderWithoutIf' declared here}}
10+
// expected-note@-1{{add 'buildOptional(_:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'if' statements without an 'else'}}{{31-31=\n static func buildOptional(_ component: <#Component#>?) -> <#Component#> {\n <#code#>\n \}}}
11+
// expected-note@-2{{add 'buildEither(first:)' and 'buildEither(second:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'if'-'else' and 'switch'}}{{31-31=\n static func buildEither(first component: <#Component#>) -> <#Component#> {\n <#code#>\n \}\n\n static func buildEither(second component: <#Component#>) -> <#Component#> {\n <#code#>\n \}}}
12+
// expected-note@-3{{add 'buildArray(_:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'for'..'in' loops}}{{31-31=\n static func buildArray(_ components: [<#Component#>]) -> <#Component#> {\n <#code#>\n \}}}
13+
static func buildBlock() -> () { }
14+
15+
static func buildBlock<T1>(_ t1: T1) -> T1 {
16+
return t1
17+
}
18+
19+
static func buildBlock<T1, T2>(_ t1: T1, _ t2: T2) -> (T1, T2) {
20+
return (t1, t2)
21+
}
22+
23+
static func buildBlock<T1, T2, T3>(_ t1: T1, _ t2: T2, _ t3: T3)
24+
-> (T1, T2, T3) {
25+
return (t1, t2, t3)
26+
}
27+
28+
static func buildBlock<T1, T2, T3, T4>(_ t1: T1, _ t2: T2, _ t3: T3, _ t4: T4)
29+
-> (T1, T2, T3, T4) {
30+
return (t1, t2, t3, t4)
31+
}
32+
33+
static func buildBlock<T1, T2, T3, T4, T5>(
34+
_ t1: T1, _ t2: T2, _ t3: T3, _ t4: T4, _ t5: T5
35+
) -> (T1, T2, T3, T4, T5) {
36+
return (t1, t2, t3, t4, t5)
37+
}
38+
}
39+
40+
func tuplifyWithoutIf<T>(_ cond: Bool, @TupleBuilderWithoutIf body: (Bool) -> T) {
41+
print(body(cond))
42+
}
43+
44+
func testDiags() {
45+
// Statements unsupported by the particular builder.
46+
tuplifyWithoutIf(true) {
47+
if $0 { // expected-error{{closure containing control flow statement cannot be used with function builder 'TupleBuilderWithoutIf'}}
48+
"hello"
49+
}
50+
}
51+
52+
tuplifyWithoutIf(true) {
53+
if $0 { // expected-error{{closure containing control flow statement cannot be used with function builder 'TupleBuilderWithoutIf'}}
54+
"hello"
55+
} else {
56+
}
57+
}
58+
59+
tuplifyWithoutIf(true) { a in
60+
for x in 0..<100 { // expected-error{{closure containing control flow statement cannot be used with function builder 'TupleBuilderWithoutIf'}}
61+
x
62+
}
63+
}
64+
}

test/decl/var/function_builders.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var globalBuilder: Int
77
func globalBuilderFunction() -> Int { return 0 }
88

99
@_functionBuilder
10-
struct Maker {} // expected-error {{function builder must provide at least one static 'buildBlock' method}}{{15-15=\n static func buildBlock(_ components: <#Component#>...) -> <#Component#> {\n <#code#>\n \}}}
10+
struct Maker {} // expected-error {{function builder must provide at least one static 'buildBlock' method}}
1111

1212
@_functionBuilder
1313
class Inventor {} // expected-error {{function builder must provide at least one static 'buildBlock' method}}

0 commit comments

Comments
 (0)