[swift-evolution] [Discussion] Removing tuple labels from the type signature
Chris Lattner
clattner at apple.com
Thu Feb 4 11:27:12 CST 2016
> On Feb 4, 2016, at 1:10 AM, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
>
> Before I start working on a proposal, I’d like to understand the problem in detail. Can someone help me understand why parts of the language treats tuple labels as type and other not?
>
> let a: (lhs: Int, rhs: Int) = (4, 5) // works
This is supposed to work because of an implicit conversion.
> (4,5).dynamicType == (lhs: 2, rhs: 6).dynamicType // true
This is not supposed to behave this way. The bug here is that we’re not encoding tuple labels in the metadata record for tuples.
> But:
>
> [(lhs: 3, rhs: 5)] == [(1,2)]
> // Binary operator ‘==‘ cannot be applied to operands of type ‘[(las: Int, rhs: Int)]’ and ‘[(Int, Int)]’
This is correctly rejected.
> [(lhs: 3, rhs: 5)].dynamicType == [(1,2)].dynamicType
> // Binary operator ‘==‘ cannot be applied to operands of type ‘Array<(las: Int, rhs: Int)>.Type’ and ‘Array<(Int, Int)>’
This is correctly rejected.
> And:
>
> struct Foo<T> {
> let bar: T
> }
>
> var foo1 = Foo(bar: (4, 5))
> var foo2 = Foo(bar: (lhs: 4, rhs: 5))
> foo1 = foo2
> // Cannot assign value of type ‘Foo<(las: Int, res: Int)>’ to type ‘Foo<(Int, Int)>’
This is correctly rejected.
> But:
>
> foo1.dynamicType == foo2.dynamicType // true
Same problem: reflection metadata isn’t being encoded, so these end up looking like they have the same dynamic type, when they shouldn’t.
-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160204/625929a4/attachment.html>
More information about the swift-evolution
mailing list