Skip to content

Some literals in patterns not processed #13101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
som-snytt opened this issue May 7, 2025 · 0 comments
Open

Some literals in patterns not processed #13101

som-snytt opened this issue May 7, 2025 · 0 comments

Comments

@som-snytt
Copy link

som-snytt commented May 7, 2025

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant