Definitions within Enum should report errors
See original GitHub issueCompiler version
Latest dotty on Scastie (3.2.0-RC1)
Minimized code
enum MyEnum {
case class Foo(n: Int)
case Constructor(field: Foo)
}
Output
enum MyEnum {
case class Foo(n: Int)
case Constructor(field: Foo)
// Not found: type Foo ^^^
}
Expectation
If definitions within enums cannot be referred to, they should be forbidden. The error message in this case should be something along the lines of:
enum MyEnum {
case class Foo(n: Int)
// case class definitions in enum not allowed.
case Constructor(field: Foo)
}
Issue Analytics
- State:
- Created a year ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Best way to define error codes/strings in Java? - Stack Overflow
As far as I am concerned, I prefer to externalize the error messages in a properties files. This will be really helpful in...
Read more >UnnecessaryDefaultInEnumSwitch - Error Prone
After the unnecessary default is removed, Error Prone will report an error if new enum constants are added in the future, to remind...
Read more >Best Practices Using Enums in .NET - Coding Helmet
This piece of code is an example of bad design. It relies on the fact that status is a particular enumeration type with...
Read more >Pyright reports error: Enum is not iterable · Issue #544 - GitHub
Pyright reports that Enum is not iterable. Python docs indicate that it is iterable and from my testing it can be iterated.
Read more >Enumeration (or enum) in C - GeeksforGeeks
Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The example at the doc link includes putting the member in the companion and how to reference it.
I agree it’s unfortunately confusing.
I think the docs already do a fairly decent job here but if someone has an idea how to improve them a suggestion or PR would be welcome.
About the error message: this will be tricky. The case class generated from
case Foo
is put in the companion object before Typer. So we see what we see in the companion object during typer. We could improve this only by turning the compiler more into a BBoM (big ball of mud) by merging desugaring and typing for enums.