question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Definitions within Enum should report errors

See original GitHub issue

Compiler 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:open
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
som-snyttcommented, Aug 24, 2022

The example at the doc link includes putting the member in the companion and how to reference it.

I agree it’s unfortunately confusing.

0reactions
oderskycommented, Aug 26, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found