Skip to content
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

TypeError in case class with member name in back ticks #12389

Closed
jarosmpost opened this issue May 3, 2021 · 5 comments
Closed

TypeError in case class with member name in back ticks #12389

jarosmpost opened this issue May 3, 2021 · 5 comments

Comments

@jarosmpost
Copy link

I receive an compiler error with the following code:

case class Abc(`abc-def`: String, abc: Long)

object Test {
  def main(args: Array[String]): Unit = println(Abc("123", 123L))
}

Scala 2.11.13 produces:

scala.reflect.internal.Types$TypeError: type mismatch;
found : String
required: Long

Scala 2.12.13 produces:

java.lang.ClassCastException:` java.lang.String cannot be cast to java.lang.Long

Work around:
Switch the order of the the members in the case class:

case class Abc(abc: Long, `abc-def`: String)

object Test {
  def main(args: Array[String]): Unit = println(Abc(123L, "123"))
}
@SethTisue
Copy link
Member

duplicate of #8831?

@som-snytt
Copy link

Like the man says.

I was gonna add that it's too bad REPL prints:

Abc(123,123)

instead of

Abc("123", 123L)

Compiler messaging should add, "Thank-you for using L for Long!"

@jarosmpost
Copy link
Author

This is a duplicate of #8831

That seems like a bug of the harder kind. Is there a chance that the fix in 2.13 will be ported back to 2.11 and 2.12 or do I have to live with the work around?

@Jasper-M
Copy link
Member

Jasper-M commented May 4, 2021

Backporting to 2.12.x might make sense. Let's give it a shot scala/scala#9607

@SethTisue
Copy link
Member

(And we no longer do 2.11.x releases.)

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

No branches or pull requests

4 participants