Closed swift-ci closed 8 years ago
Some more tuple-trouble related to this:
let c0 : (Int, Int) -> Void = { (x) -> Void in print(x.0, x.1) }
let c1 : (Int, Int) -> Void = { (x: (Int, Int)) -> Void in print(x.0, x.1) }
let c2 = { (x: (Int, Int)) -> Void in print(x.0, x.1) }
c0(1, 2)
c1(1, 2)
c2((1, 2)) // <-- NOTE: Only compiles with extra parens.
// Also note that c1 and c2 are identical except that c1 has its type given
// explicitly while c2 lets the type checker infer it.
// And look at this:
print(c1.dynamicType) // Prints ((Int, Int)) -> ()
print(c2.dynamicType) // Prints ((Int, Int)) -> ()
// And this:
print(c1.dynamicType == c2.dynamicType) // Prints true
Or perhaps more clearly formulated:
typealias BinaryIntOp_v1 = (Int, Int) -> Int
typealias BinaryIntOp_v2 = ((Int, Int)) -> Int
print(BinaryIntOp_v2.self) // Prints ((Int, Int)) -> Int
print(BinaryIntOp_v2.self) // Prints ((Int, Int)) -> Int
let areRepresentingTheSameType = BinaryIntOp_v1.self == BinaryIntOp_v2.self // (alt-click the "==" and read doc.)
print(areRepresentingTheSameType) // Prints true
let add_v1: BinaryIntOp_v1 = (+)
let add_v2: BinaryIntOp_v2 = (+) // Or both could have been eg: { return $0 + $1 }
let ra = add_v1(1, 2)
let rb = add_v2((1, 2)) // NOTE: Needs these extra parens (otherwise error: "Extra argument in call")
let rc = (add_v1 as BinaryIntOp_v2)((1, 2)) // NOTE: I am type casting these to an identical type ...
let rd = (add_v2 as BinaryIntOp_v1)(1, 2) // ... in order to swap which one of them need extra parens ...
Comment by Vladimir (JIRA)
Any news on this ?
Can't reproduce on current master. Seems to have been fixed in the meantime.
I've created a separate issue for the stuff demonstrated by my code examples above, here: https://bugs.swift.org/browse/SR-2216
Environment
IBM Swift Sandbox Swift Ver. 3.0 (Jun 6, 2016) Target: x86_64-ubuntu-linux-gnuAdditional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash | |Assignee | None | |Priority | Medium | md5: ceeff5fc884b27df509c065f88320a3brelates to:
Issue Description:
This code crashes the compiler, as I understand from the output: