I found this scala problem: https://issues.scala-lang.org/browse/SI-4939
It seems we can define a method whose name is a number:
scala> object Foo { val 1 = 2 } defined module Foo
But we cannot call it:
scala> Foo.1 <console>:1: error: ';' expected but double literal found. Foo.1
And we can call it inside the object:
scala> object O { val 1 = 1; def x = 1 } defined module O scala> Ox res1: Int = 1
And the error will follow:
scala> object O { val 1 = 2; def x = 1 } defined module O scala> Ox scala.MatchError: 2 at O$.<init>(<console>:5) at O$.<clinit>(<console>) at .<init>(<console>:7) at .<clinit>(<console>) at RequestResult$.<init>(<console>:9)
I use scalac -Xprint:typer to view the code, part val 1 = 2 :
<synthetic> private[this] val x$1: Unit = (2: Int(2) @unchecked) match { case 1 => () }
It shows that the method name is changed to x$1 and can be called inside this object.
And the solution to this problem: Do not fix
I want to know if there is a reason allowing the number to be the name of the method? Is there any case where we need to use the number method?
Freewind
source share