You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
enumTag[A]:caseMyTupleextendsTag[(String, String)]
defprintIt[A](t: Tag[A], a: A):Unit=
t matchcaseTag.MyTuple=> println(a._1)
Output
value _1 is not a member of A
where: A is a type in method printIt with bounds >: (String, String) and <: (String, String)
Expectation
Should compile fine, since the compiler knows that it is <: (String, String) and (String, String) should have _1. FWIW, annotating the type works. I.e.
felher
changed the title
Can't call _.1 on values inferred by a GADT to be a tuple
Can't call ._1 on values inferred by a GADT to be a tuple
Dec 26, 2022
felher
changed the title
Can't call ._1 on values inferred by a GADT to be a tuple
Can't call ._1 on values inferred by a GADT match to be a tuple
Dec 26, 2022
Both the case class representation and the generic representation of 2-tuple print as (String, String) – if you reach in and make them print differently, you find that in this case the lower bound is the Tuple2 case class but the upper bound is the generic version.
But that mismatch doesn't itself mean that something has already gone wrong. It's the upper bound that matters for member selection and calling ._1 on the generic version should of course work, and in normal circumstances it does. But not when GADT selection healing is needed, apparently!
A related recent fix to typedSelect was #16638, making extension method lookup take GADT constraints into account. typedSelect also has special code for selections on generic tuples, so we guess that code needs a comparable change.
Compiler version
3.2.1
Minimized code
Output
Expectation
Should compile fine, since the compiler knows that it is
<: (String, String)
and(String, String)
should have_1
. FWIW, annotating the type works. I.e.compiles fine.
Scastie Link:
https://scastie.scala-lang.org/4sovEbRjTJOlv0g5WNEUTw
The text was updated successfully, but these errors were encountered: