Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6356043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:53:17+00:00 2026-05-24T22:53:17+00:00

I found this issue of scala: https://issues.scala-lang.org/browse/SI-4939 Seems we can define a method whose

  • 0

I found this issue of scala: https://issues.scala-lang.org/browse/SI-4939

Seems we can define a method whose name is a number:

scala> object Foo { val 1 = 2 }
defined module Foo

But we can’t invoke it:

scala> Foo.1
<console>:1: error: ';' expected but double literal found.
       Foo.1

And we can invoke it inside the object:

scala> object O { val 1 = 1; def x = 1 }
defined module O
scala> O.x
res1: Int = 1

And follow will throw error:

scala> object O { val 1 = 2; def x = 1 }
defined module O
scala> O.x
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 see the code, the val 1 = 2 part is:

<synthetic> private[this] val x$1: Unit = (2: Int(2) @unchecked) match {
    case 1 => ()
}

From it, we can see the method name changed to x$1, and only can be invoked inside that object.

And the resolution of that issue is: Won’t Fix

I want to know is there any reason to allow a number to be the name of a method? Is there any case we need to use a “number” method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:53:20+00:00Added an answer on May 24, 2026 at 10:53 pm

    There is no name “1” being bound here. val 1 = 2 is a pattern-matching expression, in much the same way val (x,2) = (1,2) binds x to 1 (and would throw a MatchError if the second element were not thet same). It’s allowed because there’s no real reason to add a special case to forbid it; this way val pattern matching works (almost) exactly the same way as match pattern-matching.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't resolve this issue, I found a similar question here but: setting the
Has anyone else had this issue and found a working solution? I've enabled the
I know this issue has been touched on here but I have not found
I've been struggling with this issue for a little while now. Found several posts
found this regex: insert every 10 characters: $text = preg_replace(|(.{10})|u, \${1}. , $text); can
I found this issue with distanceFromLocation function where the return value is not accurate.
I found this issue to always happen and not consistent. This issue causing jquery
I am having issues with the following code in Scala import org.junit.Test import org.junit.Assert._
I've found this issue with t-tests and chi-squared in R but I assume this
We found this issue while implementing a reconnect logic for a WS endpoint using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.