Skip to content

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

Closed
@aappddeevv

Description

@aappddeevv

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions