-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
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
Labels
No labels