Skip to content

Pattern matching in val and match return different types #10315

Open
@Atry

Description

@Atry

According to Scala language specification 4.1, the following code should have the same behavior:

Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions for evaluation. Or try :help.

scala> val (a: Any, b: Any) = (1, 2) 
a: Any = 1
b: Any = 2
Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions for evaluation. Or try :help.

scala> val $x = (1, 2) match { case (a: Any, b: Any) => (a, b) }; val a = $x._1; val b = $x._2 
$x: (Int, Int) = (1,2)
a: Int = 1
b: Int = 2

However, the type of a and b are different in the two examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)language specpatmattyper

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions