You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[BuilderTransform] Verify that builder type has at least one accessible build{Partial}Block
Check accessibility of all build{Partial}Block overloads and
diagnose if none of them are as accessible as type, otherwise
swift interfaces could end up with invalid result builder
declarations when type is public and all builder methods are
internal.
Resolves: rdar://104384604
Copy file name to clipboardExpand all lines: test/attr/attr_result_builder.swift
+72Lines changed: 72 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4,3 +4,75 @@
4
4
structMyBuilder{
5
5
staticfunc buildBlock(_:Any...)->Any{}
6
6
}
7
+
8
+
// rdar://104384604 - empty result builder in swiftinterface file
9
+
@resultBuilder
10
+
publicstructTestInvalidBuildBlock1{
11
+
// expected-error@-1 {{result builder must provide at least one static 'buildBlock' as accessible as result builder type 'TestInvalidBuildBlock1' (which is public)}}
12
+
staticfunc buildBlock(_:Int)->Int{42}
13
+
}
14
+
15
+
@resultBuilder
16
+
publicstructTestInvalidBuildBlock2{ // Ok
17
+
staticfunc buildBlock(_:Int)->Int{42}
18
+
publicstaticfunc buildBlock(_:String)->String{""}
19
+
}
20
+
21
+
@resultBuilder
22
+
publicstructTestInvalidBuildPartialBlockFirst1{
23
+
// expected-error@-1 {{result builder must provide at least one static 'buildPartialBlock(first:)' as accessible as result builder type 'TestInvalidBuildPartialBlockFirst1' (which is public)}}
24
+
staticfunc buildPartialBlock(first:Int)->Int{ first }
25
+
publicstaticfunc buildPartialBlock(accumulated:Int, next:Int)->Int{ accumulated + next }
26
+
}
27
+
28
+
@resultBuilder
29
+
publicstructTestInvalidBuildPartialBlockFirst2{ // Ok
30
+
staticfunc buildPartialBlock(first:Int)->Int{ first }
31
+
publicstaticfunc buildPartialBlock<T>(first:T)->T{ first }
32
+
publicstaticfunc buildPartialBlock(accumulated:Int, next:Int)->Int{ accumulated + next }
// expected-error@-1 {{result builder must provide at least one static 'buildPartialBlock(accumulated:next:)' as accessible as result builder type 'TestInvalidBuildPartialBlockAccumulated1' (which is public)}}
38
+
publicstaticfunc buildPartialBlock(first:Int)->Int{ first }
39
+
privatestaticfunc buildPartialBlock(accumulated:Int, next:Int)->Int{ accumulated + next }
40
+
}
41
+
42
+
@resultBuilder
43
+
publicstructTestInvalidBuildPartialBlockAccumulated2{ // Ok
44
+
publicstaticfunc buildPartialBlock<T>(first:T)->T{ first }
0 commit comments