Skip to content

Can't call ._1 on values inferred by a GADT match to be a tuple #16590

Closed
@felher

Description

@felher

Compiler version

3.2.1

Minimized code

enum Tag[A]:
  case MyTuple extends Tag[(String, String)]

def printIt[A](t: Tag[A], a: A): Unit =
  t match
    case Tag.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.

    case Tag.MyTuple => println((a: (String, String))._1)

compiles fine.

Scastie Link:

https://scastie.scala-lang.org/4sovEbRjTJOlv0g5WNEUTw

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions