[swift-evolution] Implicit Optionals for Tuples & Tuples as Function Parameter

John McCall rjmccall at apple.com
Fri Nov 11 15:59:37 CST 2016


> On Nov 11, 2016, at 1:37 PM, Nevin Brackett-Rozinsky via swift-evolution <swift-evolution at swift.org> wrote:
> I’ll mention this here since it’s related to tuples and optionals. Starting with this setup:
> 
> var x, y: Int?
> func f() -> (Int, Int) { return (0, 1) }
> 
> This fails to compile:
> 
> (x, y) = f()  // Error: Cannot express tuple conversion '(Int, Int)' to '(Int?, Int?)'
> 
> But this works fine:
> 
> func g() -> Int { return 2 }
> (x, y) = (g(), g())
> 
> What is going on, why does the first one fail, and is this a bug or does it need a proposal to fix?

It's a bug.  The error message is actually subtly telling you the problem: the type-checker literally can't express the opaque tuple conversion in the AST; when it's a raw tuple expression, it can push the element conversions into the element expressions, but it can't do that with an opaque tuple.  It's a silly restriction because of an unfortunate representational decision.

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161111/0cf4d159/attachment.html>


More information about the swift-evolution mailing list