Skip to content

Fix compiler crash for repeated Enums #4530

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

Merged
merged 10 commits into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ object DesugarEnums {
private def enumScaffolding(implicit ctx: Context): List[Tree] = {
def enumDefDef(name: String, select: String) =
DefDef(name.toTermName, Nil, Nil, TypeTree(), valuesDot(select))

val privateValuesDef =
ValDef(nme.DOLLAR_VALUES, TypeTree(),
New(TypeTree(defn.EnumValuesType.appliedTo(enumClass.typeRef :: Nil)), ListOfNil))
New(TypeTree(defn.EnumValuesType.appliedTo(enumClass.typeRef :: Nil)), ListOfNil))
.withFlags(Private)
val valueOfDef = enumDefDef("enumValue", "fromInt")
val withNameDef = enumDefDef("enumValueNamed", "fromName")
Expand Down Expand Up @@ -195,7 +196,8 @@ object DesugarEnums {
/** Expand a module definition representing a parameterless enum case */
def expandEnumModule(name: TermName, impl: Template, mods: Modifiers, pos: Position)(implicit ctx: Context): Tree = {
assert(impl.body.isEmpty)
if (impl.parents.isEmpty)
if (!enumClass.exists) EmptyTree
else if (impl.parents.isEmpty)
expandSimpleEnumCase(name, mods, pos)
else {
def toStringMeth =
Expand Down
10 changes: 10 additions & 0 deletions tests/neg/enum-repeated-4470.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object RepeatedEnum {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our convention is to name our regression test files like i4470.scala. If you have mutiple test cases: i4470a.scala, i4470b.scala

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty, will rename the files thanks for the hint.


enum Maybe { // error // error
case Foo
}

enum Maybe { // error
case Foo
}
}
10 changes: 10 additions & 0 deletions tests/neg/enum-repeated-extend-4470.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object RepeatedExtendEnum {

enum Maybe[T] { // error // error
case Foo extends Maybe[Int]
}

enum Maybe[T] { // error
case Foo extends Maybe[Int]
}
}