Skip to content

Some literals in patterns not processed #13101

@som-snytt

Description

@som-snytt

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 scala/scala#11056 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions