Skip to content

crash when extending trait that extends jl.Enum in REPL #9324

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

Closed
bishabosha opened this issue Jul 8, 2020 · 2 comments
Closed

crash when extending trait that extends jl.Enum in REPL #9324

bishabosha opened this issue Jul 8, 2020 · 2 comments

Comments

@bishabosha
Copy link
Member

bishabosha commented Jul 8, 2020

Minimized code

play these statements in the repl (launched with dotr 0.25.0-RC2)

scala> trait T extends java.lang.Enum[T]
scala> class TEnum extends T

Output (click arrow to expand)

error while transforming new Enum[T]
error while transforming new Enum[T]()
error while transforming () extends Enum[T](), T {}
error while transforming class TEnum() extends Enum[T](), T {}
error while transforming () extends Object(), _root_.scala.Serializable { this: rs$line$2.type =>
  class TEnum() extends Enum[T](), T {}
}
error while transforming @scala.annotation.internal.SourceFile("rs$line$2") final module class rs$line$2$
  (
) extends Object(), _root_.scala.Serializable { this: rs$line$2.type =>
  class TEnum() extends Enum[T](), T {}
}
error while transforming package <empty> {
  final lazy module val rs$line$2: rs$line$2$ = new rs$line$2$()
  @scala.annotation.internal.SourceFile("rs$line$2") final module class 
    rs$line$2$
  () extends Object(), _root_.scala.Serializable { this: rs$line$2.type =>
    class TEnum() extends Enum[T](), T {}
  }
}
Exception in thread "main" java.lang.AssertionError: assertion failed: denotation class Enum invalid in run 2. ValidFor: Period(1..44, run = 3)
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.updateValidity(Denotations.scala:688)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:718)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:773)
	at dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:119)
	at dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:113)
	at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:106)
	at dotty.tools.dotc.core.SymDenotations$.stillValidInOwner(SymDenotations.scala:2362)
	at dotty.tools.dotc.core.SymDenotations$.stillValid(SymDenotations.scala:2358)
	at dotty.tools.dotc.core.Symbols$Symbol.isValidInCurrentRun(Symbols.scala:144)
	at dotty.tools.dotc.core.Types$NamedType.computeSymbol(Types.scala:1942)
	at dotty.tools.dotc.core.Types$NamedType.symbol(Types.scala:1937)
	at dotty.tools.dotc.core.Substituters$.subst1(Substituters.scala:27)
	at dotty.tools.dotc.core.Substituters$Subst1Map.apply(Substituters.scala:165)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:5003)
	at dotty.tools.dotc.core.Types$LazyRef$.apply$$anonfun$1(Types.scala:2632)
	at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2645)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:4996)
	at dotty.tools.dotc.core.Types$LazyRef$.apply$$anonfun$1(Types.scala:2632)
	at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2645)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:4996)
	at dotty.tools.dotc.core.Types$LazyRef$.apply$$anonfun$1(Types.scala:2632)
	at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2645)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:4996)
	at dotty.tools.dotc.core.Types$LazyRef$.apply$$anonfun$1(Types.scala:2632)
	at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2645)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:4996)
	at dotty.tools.dotc.core.Types$LazyRef$.apply$$anonfun$1(Types.scala:2632)
	at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2645)
	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:402)
	at dotty.tools.dotc.core.TypeComparer.compareNamed$1(TypeComparer.scala:274)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:276)
	at dotty.tools.dotc.core.TypeComparer.op$1(TypeComparer.scala:1131)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1150)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:162)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:172)
	at dotty.tools.dotc.core.TypeComparer.isSubArg$1(TypeComparer.scala:1346)
	at dotty.tools.dotc.core.TypeComparer.recurArgs$1(TypeComparer.scala:1351)
	at dotty.tools.dotc.core.TypeComparer.isSubArgs(TypeComparer.scala:1354)
	at dotty.tools.dotc.core.TypeComparer.checkSubArgs$1(TypeComparer.scala:905)
	at dotty.tools.dotc.core.TypeComparer.loop$3(TypeComparer.scala:907)
	at dotty.tools.dotc.core.TypeComparer.isMatchingApply$1(TypeComparer.scala:922)
	at dotty.tools.dotc.core.TypeComparer.compareAppliedType2$1(TypeComparer.scala:1015)
	at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:498)
	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:448)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:345)
	at dotty.tools.dotc.core.TypeComparer.op$1(TypeComparer.scala:1131)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1150)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:162)
	at dotty.tools.dotc.core.TypeComparer.tryBaseType$1(TypeComparer.scala:706)
	at dotty.tools.dotc.core.TypeComparer.compareAppliedType2$1(TypeComparer.scala:1023)
	at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:498)
	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:357)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:345)
	at dotty.tools.dotc.core.TypeComparer.op$1(TypeComparer.scala:1131)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1150)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:162)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:172)
	at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:128)
	at dotty.tools.dotc.core.Types$Type.$less$colon$less(Types.scala:910)
	at dotty.tools.dotc.core.TypeOps$.check$1(TypeOps.scala:591)
	at dotty.tools.dotc.core.TypeOps$.checkOverlapsBounds$1(TypeOps.scala:594)
	at dotty.tools.dotc.core.TypeOps$.boundsViolations$$anonfun$2(TypeOps.scala:598)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
	at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
	at scala.collection.AbstractIterable.foreach(Iterable.scala:920)
	at scala.collection.IterableOps$WithFilter.foreach(Iterable.scala:890)
	at dotty.tools.dotc.core.TypeOps$.boundsViolations(TypeOps.scala:600)
	at dotty.tools.dotc.typer.Checking$.checkBounds(Checking.scala:72)
	at dotty.tools.dotc.typer.Checking$.checkBounds(Checking.scala:83)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:282)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:262)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:270)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1371)
	at scala.collection.immutable.List.mapConserve(List.scala:472)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1371)
	at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:58)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$7$$anonfun$1(PostTyper.scala:301)
	at dotty.tools.dotc.transform.SuperAccessors.wrapTemplate(SuperAccessors.scala:199)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$4(PostTyper.scala:301)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.withNoCheckNews(PostTyper.scala:97)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:302)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1349)
	at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:54)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:324)
	at dotty.tools.dotc.transform.MacroTransform$Transformer.transformStat$1(MacroTransform.scala:42)
	at dotty.tools.dotc.transform.MacroTransform$Transformer.transformStats$$anonfun$1(MacroTransform.scala:45)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:67)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:83)
	at dotty.tools.dotc.transform.MacroTransform$Transformer.transformStats(MacroTransform.scala:45)
	at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:61)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$7$$anonfun$1(PostTyper.scala:301)
	at dotty.tools.dotc.transform.SuperAccessors.wrapTemplate(SuperAccessors.scala:199)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$4(PostTyper.scala:301)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.withNoCheckNews(PostTyper.scala:97)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:302)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1349)
	at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:54)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:324)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1371)
	at scala.collection.immutable.List.mapConserve(List.scala:472)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1371)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1369)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1356)
	at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:54)
	at dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:388)
	at dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:295)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:296)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:181)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:191)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:199)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:206)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:148)
	at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:153)
	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:163)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:233)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:196)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:129)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:132)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:151)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:132)
	at dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.repl.Main.main(Main.scala)
@bishabosha bishabosha changed the title REPL session triggers crash with F-Bounded java-style enum crash when extending trait that extends jl.Enum in REPL Aug 7, 2020
@griggt
Copy link
Contributor

griggt commented Sep 25, 2020

Fixed by #9487?

Does not crash in the 0.27.0-RC1 REPL:

scala> trait T extends java.lang.Enum[T]
// defined trait T

scala> class TEnum extends T
1 |class TEnum extends T
  |      ^
  |class TEnum cannot extend java.lang.Enum: only enums defined with the enum syntax can

@bishabosha
Copy link
Member Author

if you use -source:3.0-migration then classes may extend java.lang.Enum, however there is now another error:

scala> trait T extends java.lang.Enum[T]
// defined trait T

scala> class TEnum extends T
1 |class TEnum extends T
  |      ^
  |wrong number of arguments at functionalInterfaces for (_$name: String, _$ordinal: Int): Enum: (TEnum.super.<init> : (_$name: String, _$ordinal: Int): Enum), expected: 2, found: 0

bishabosha added a commit to dotty-staging/dotty that referenced this issue Oct 16, 2020
bishabosha added a commit to dotty-staging/dotty that referenced this issue Oct 16, 2020
bishabosha added a commit to dotty-staging/dotty that referenced this issue Oct 16, 2020
bishabosha added a commit to dotty-staging/dotty that referenced this issue Oct 16, 2020
bishabosha added a commit that referenced this issue Oct 19, 2020
fix #9324: forbid no-arg java.lang.Enum ctor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants