bug icon indicating copy to clipboard operation
bug copied to clipboard

Some literals in patterns not processed

Open som-snytt opened this issue 7 months ago • 0 comments

Questions are not bug reports

Sorry in advance to Seth if this turns out to be a question. He can come after me.

Reproduction steps

Scala version: 2.13.16

Welcome to Scala 2.13.16 (OpenJDK 64-Bit Server VM, Java 23.0.2).
Type in expressions for evaluation. Or try :help.

scala> def f(x: Any) = x match { case 3.14: Double => x }
                                          ^
       error: '=>' expected but ':' found.

scala> def f(x: Any) = x match { case 3.14 => x }
def f(x: Any): Any

scala> def f(x: Any) = x match { case x: 3.14 => x }
def f(x: Any): Any

scala> def f(x: Any) = x match { case x: Double => x }
def f(x: Any): Double

scala> def f(x: Any): Double = x match { case x: 3.14 => x }
                                                         ^
       error: type mismatch;
        found   : Any
        required: Double

scala>
:quit

Problem

Welcome to Scala 3.6.4 (23.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> def f(x: Any) = x match { case 3.14: Double => x }
def f(x: Any): Any

scala> def f(x: Any) = x match { case x: Double => x }
def f(x: Any): Double

scala> def f(x: Any) = x match { case x: 3.14 => x }
def f(x: Any): Double

scala>

It accepts the funny syntax and also infers Double for the last case.

Noticed at related https://github.com/scala/scala/pull/11056#issue-3044307662

som-snytt avatar May 07 '25 00:05 som-snytt