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 6817225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:01:28+00:00 2026-05-26T21:01:28+00:00

I get a compile error if I name some case objects r0, r1 and

  • 0

I get a compile error if I name some case objects “r0”, “r1” and so on.
If I use different names, the code compile and run as expected.
A rational for that would be very welcome !

the code:

package qndTests2

sealed abstract case class Reg()
trait RReg
trait RRegNotPc extends RReg
trait LowReg extends RReg
sealed abstract case class LowRegClass() extends Reg with LowReg
sealed abstract case class RRegNotPcClass() extends Reg with RRegNotPc
case object R0 extends LowRegClass
case object R1 extends LowRegClass
case object R2 extends RRegNotPcClass
case object R3 extends Reg with RReg

sealed abstract case class Base()
trait T1
trait T2 extends T1
trait T3 extends T1
sealed abstract case class CaseClassT3() extends Base with T3
sealed abstract case class CaseClassT2() extends Base with T2
case object r0 extends CaseClassT3
case object r1 extends CaseClassT3
case object r2 extends CaseClassT2
case object r3 extends Base with T1

object test {
  def regToInt(r: RReg): Int = {
    r match{
      case R0 => 0
      case R1 => 1
      case R2 => 2
      case R3 => 3
    }
  }
  def toInt(r: T1): Int = {
    r match{
      case r0 => 0
      case r1 => 1   //error: unreachable code
      case r2 => 2   //error: unreachable code
      case r3 => 3   //error: unreachable code
    }
  }
  def main(args: Array[String]): Unit = {
    println(toInt(r0))
    println(toInt(r1))
    println(regToInt(R0))
    println(regToInt(R3))
  }
}

the package “qndTests2” contains only one file, Test.scala, and the full content of the file is above.
Replace “r0” ~ “r3” by “A” ~ “D”, and it compiles !
I don’t the reason why…
am I just very tired, overlooking something obvious ???

  • 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-26T21:01:28+00:00Added an answer on May 26, 2026 at 9:01 pm

    It’s not about r0~r3, it’s about lowercase vs uppercase. See this previous question.

    Your call whether it’s a bug or a feature of the language spec, but it’s there, section 8.1.1:

    A variable pattern x is a simple identifier which starts with a lower case letter. It
    matches any value, and binds the variable name to that value.

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

Sidebar

Related Questions

In the following code, I get a compile time error: ByRef Argument type mismatch.
In the following code, I get a compile time error because i is treated
For the attached code, I get the following compile time error : exception during
I get an error when I compile this code: using System; public struct Vector2
When trying to compile my class I get an error: The constant 'NamespaceName.ClassName.CONST_NAME' cannot
I get a compile error, which I'm slightly confused about. This is on VS2003.
When I compile my application , I get following compile error. Unable to find
How can I get this to compile? The error is when I start using
I get the following error when I try to compile an asp.net site using
When I compile a project I get this error: C:\DATOSA~1\FAXENG~1>nmake /f Makefile.vc clean Microsoft

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.