Enum case can't be defined in terms of itself
See original GitHub issueCompiler version
3.0.0-M3
Minimized code
enum Opt[T] {
case Nn extends Opt[Nothing] with Comparable[Nn.type]
def compareTo(nn: Nn.type) = 0
}
Output
2 | case Nn extends Opt[Nothing] with Comparable[Nn.type]
| ^
| Recursive value Nn needs type
Expectation
I expected it to work much like the Scala 2 equivalent:
sealed trait Opt[T]
case object Nn extends Opt[Nothing] with Comparable[Nn.type] {
def compareTo(nn: Nn.type) = 0
}
Btw, this error was also mentioned in #11249 but the original issue there is about vals.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Can you define an enum to represent values explicitly known ...
The trick is to define one additional case, unknown with an associated value of type RawValue . This new case handles all the...
Read more >for case enum syntax | Apple Developer Forums
for case .MyEnumCase (let value) in enumValues. But tests in Xcode 7 show that this sort of thing won't compile (with suitable declaration...
Read more >Access control for enum cases - Pitches - Swift Forums
Introduction. Today, Swift doesn't allow access control modifiers on enum cases, unlike properties, methods and other kinds of declarations.
Read more >Why Swift Enums with Associated Values Cannot Have a Raw ...
The Problem with Associated Values We had to do this because Swift doesn't allow us to have both: raw values and associated values...
Read more >Swift Enumerations - AndyBargh.com
When defining enumeration cases, each case within the enumeration should also be unique. For example we couldn't define two cases called red within...
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 Free
Top 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
Weird, I would have sworn that this worked in Scala 2… 🤔
A workaround that works in both Scala 2 and Scala 3 (!):
In fact, in Scala 3 we can simplify it to just:
@yuriy-yarosh your example is a duplicate of #9177 which was closed 😕