Swift no longer infers type of XCTAssertEqual arguments
| Originator: | jlieske | ||
| Number: | rdar://17587040 | Date Originated: | 08-Jul-2014 00:18 AM |
| Status: | Closed | Resolved: | Resolved |
| Product: | Developer Tools | Product Version: | Xcode 6 beta 3: Version 6.0 (6A254o) |
| Classification: | Other Bug | Reproducible: | Always |
The Swift language can infer the concrete types of arguments passed to generic functions. In previous beta versions of the compiler, it would allow shorthand notation for enum values in such arguments. In the beta 3 compiler, however, XCTAssertEqual no long infers the correct type.
This is the essence of the code the exhibits the issue. I no longer have the Beta 2 Swift compiler, so I can’t completely verify that it compiled with Beta 2. However, the error definite on Beta 3.
import XCTest
enum SimpleToken {
case Name(String)
case Number(Int)
}
extension SimpleToken : Printable {
var description: String { get {
switch self {
case Name(let value): return "Name(\(value))"
case Number(let value): return "Number(\(value))"
}
}}
}
extension SimpleToken : Equatable {
}
func ==(lhs: SimpleToken, rhs: SimpleToken) -> Bool {
switch lhs {
case .Name(let lval): switch rhs {
case .Name(let rval): return lval == rval
default: return false
}
case .Number(let lval): switch rhs {
case .Number(let rval): return lval == rval
default: return false
}
}
}
class TryPrintableEnum: XCTestCase {
func testExample() {
XCTAssertEqual(SimpleToken.Number(1), .Name("Hello"))
}
}
The error in the Beta 3 compiler is:
TryPrintableEnum.swift:44:48: error: '(@auto_closure () -> SimpleToken).Type' does not have a member named 'Name'
XCTAssertEqual(SimpleToken.Number(1), .Name("Hello"))
^
Note that the inferred type should be SimpleToken, but it resolves to Type.
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!
This was fixed in Xcode 6.2.