Skip to content

enum case object not accessible in package object at runtime #7287

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

Closed
aappddeevv opened this issue Sep 22, 2019 · 4 comments
Closed

enum case object not accessible in package object at runtime #7287

aappddeevv opened this issue Sep 22, 2019 · 4 comments

Comments

@aappddeevv
Copy link

aappddeevv commented Sep 22, 2019

I'm not sure I have the conditions completely nailed down for this but I can say that I get errors and they are fixed in a specific way.

When defining an enum with a case object vs a case class e.g.:

enum Color derives Eql {
  case Unknown
  case Blue(v: Int)
  case Red(v: Int)
}

If I try to use this using a toplevel definition (no surrounding object) in my test source code:

val testData = Seq(("blah", Color.Unknown), ("red", Color.Red(10)))
...
// use testData in a test

The process cannot see Color.Unknown in testData and I get an error at runtime:

[error] Test myapp.TestParsing.test_colors failed: java.lang.NoSuchFieldError: Unknown, took 0.003 sec
[error]     at myapp.data$package$.actionDates(data.scala:139)
[error]     at myapp.TestParsing.test_colors(TestParsing.scala:66)
[error]     ...

If I move the definition of testData into the main project, vs the test itself, everything runs fine. Hence, no runtime error.

If I define Unknown as case Unknown(dummy: Int = -1) and use Color.Unknown() everywhere, everything runs fine. Using case Unknown() does not work.

I have seen this error before. But the consumer was in the same main application vs the test module so I do not think this is a test framework issue.

dotty 0.18

@aappddeevv aappddeevv changed the title enum case object not accessible in package object enum case object not accessible in package object at runtime Sep 22, 2019
@bishabosha
Copy link
Member

I have also experienced this error in other code, where the bytecode points to the wrong location of an enum constant, but it only occurs under some incremental compilation that is hard to reproduce, If I compile from clean, it goes away.

@aappddeevv
Copy link
Author

Clean does not help me in my case. I used -Xprint:frontend but I could not see anything obvious that would cause this problem. It almost feels like an initialization order problem.

@smarter
Copy link
Member

smarter commented Sep 22, 2019

can you provide a link to a git branch where the problem can be reproduced?

@aappddeevv
Copy link
Author

Alright, here it is: https://github.com/aappddeevv/dotty-issue-7287

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