Swift Block Type Inference Failure
| Originator: | DaNmarner | ||
| Number: | rdar://21475622 | Date Originated: | 6/20/2015 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 7 beta (7A120f) |
| Classification: | Reproducible: | Always |
Summary:
Block literals have trouble inferring its type, when the type conforms to multiple protocols. This only happens in certain circumstances.
Steps to Reproduce:
The following example will not compile in Xcode 7 beta 1:
protocol A {
var x: B { get set }
}
protocol B {}
struct B1:B {}
struct M: A, B {
var x: B
}
func f(bs: [B->B]) -> B {
return B1()
}
f([ { M(x: $0) } ]) // '(B) -> M' is not compatible with expected type 'B -> B'
Expected Results:
Should compile, as there's enough information for the compiler
Actual Results:
Does not compile unless the type is explicitly added in the last line of the sample code:
f([ {b -> B in M(x: b) } ]) // ok
Version:
Xcode 7 beta (7A120f)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!