Skip to content

type constructor in union causes compiler crash instead of giving an error #3161

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
allanrenucci opened this issue Sep 22, 2017 · 3 comments
Closed

Comments

@allanrenucci
Copy link
Contributor

allanrenucci commented Sep 22, 2017

#3061 broke compilation of https://github.com/lampepfl/dotty-example-project/blob/master/src/main/scala/UnionTypes.scala

Here is a minimised test case:

object UnionTypes {
  trait List[A]
  class Empty() extends List[Nothing]
  class Cons[A](h: A, t: List[A]) extends List[A]

  def test: Unit = {
    val list: Cons | Empty = null
  }
}
Stacktrace
exception occurred while typechecking tests/allan/Test.scala

exception occurred while compiling tests/allan/Test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: HKTypeLambda(List(A), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),Nothing),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),Any))), AppliedType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class )),UnionTypes$)),Cons),List(ParamRef(A)))) TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class )),UnionTypes$)),Empty)
at scala.Predef$.assert(Predef.scala:219)
at dotty.tools.dotc.core.Types$OrType.(Types.scala:2398)
at dotty.tools.dotc.core.Types$CachedOrType.(Types.scala:2425)
at dotty.tools.dotc.core.Types$OrType$.apply(Types.scala:2430)
at dotty.tools.dotc.typer.TypeAssigner.$anonfun$assignType$24(TypeAssigner.scala:471)
at dotty.tools.dotc.typer.TypeAssigner.inSameUniverse(TypeAssigner.scala:556)
at dotty.tools.dotc.typer.TypeAssigner.assignType(TypeAssigner.scala:471)
at dotty.tools.dotc.typer.TypeAssigner.assignType$(TypeAssigner.scala:470)
at dotty.tools.dotc.typer.Typer.assignType(Typer.scala:66)
at dotty.tools.dotc.typer.Typer.$anonfun$typedOrTypeTree$1(Typer.scala:1089)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedOrTypeTree(Typer.scala:1085)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1651)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1675)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1664)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1675)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1690)
at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1688)
at dotty.tools.dotc.typer.Namer.$anonfun$typedAheadType$1(Namer.scala:940)
at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:933)
at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:940)
at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1116)
at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:732)
at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:781)
at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:759)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:228)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:206)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:345)
at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:1581)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1606)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1674)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1690)
at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1688)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1712)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1735)
at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:620)
at dotty.tools.dotc.typer.Typer.$anonfun$typedBlock$1(Typer.scala:623)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:622)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1635)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1675)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1690)
at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1688)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1747)
at dotty.tools.dotc.typer.Typer.$anonfun$typedDefDef$1(Typer.scala:1305)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1287)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1616)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1674)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1690)
at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1688)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1712)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1735)
at dotty.tools.dotc.typer.Typer.$anonfun$typedClassDef$1(Typer.scala:1405)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1335)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1619)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1674)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1690)
at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1688)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1712)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1735)
at dotty.tools.dotc.typer.Typer.$anonfun$typedPackageDef$1(Typer.scala:1518)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1505)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1658)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1675)
at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1690)
at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1688)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1747)
at dotty.tools.dotc.typer.FrontEnd.$anonfun$typeCheck$1(FrontEnd.scala:64)
at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:62)
at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$5(FrontEnd.scala:93)
at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$5$adapted(FrontEnd.scala:93)
at scala.collection.immutable.List.foreach(List.scala:389)
at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:93)
at dotty.tools.dotc.Run.$anonfun$compileUnits$3(Run.scala:124)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at dotty.tools.dotc.util.Stats$.trackTime(Stats.scala:47)
at dotty.tools.dotc.Run.$anonfun$compileUnits$2(Run.scala:122)
at dotty.tools.dotc.Run.$anonfun$compileUnits$2$adapted(Run.scala:120)
at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:191)
at dotty.tools.dotc.Run.$anonfun$compileUnits$1(Run.scala:120)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:86)
at dotty.tools.dotc.Run.compileUnits(Run.scala:108)
at dotty.tools.dotc.Run.compileSources(Run.scala:95)
at dotty.tools.dotc.Run.compile(Run.scala:79)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:26)
at dotty.tools.dotc.Driver.process(Driver.scala:124)
at dotty.tools.dotc.Driver.process(Driver.scala:93)
at dotty.tools.dotc.Driver.process(Driver.scala:105)
at dotty.tools.dotc.Driver.main(Driver.scala:132)
at dotty.tools.dotc.Main.main(Main.scala)


@smarter
Copy link
Member

smarter commented Sep 23, 2017

This shouldn't crash but the code is wrong: it should be Cons[Any] | Empty or something.

@smarter smarter changed the title Compiler crashes on union type type constructor in union causes compiler crash instead of giving an error Sep 26, 2017
smarter added a commit to smarter/dotty-example-project that referenced this issue Sep 26, 2017
Types in union need to be fully applied, the previous code was wrong but
happened to work before scala/scala3#3061. See
scala/scala3#3161.
@odersky odersky closed this as completed Sep 28, 2017
@smarter
Copy link
Member

smarter commented Sep 28, 2017

@odersky Did you intend to close this? It still crashes on master.

@smarter smarter reopened this Sep 28, 2017
@odersky
Copy link
Contributor

odersky commented Sep 28, 2017

Ah I thought you had fixed it!

odersky added a commit to dotty-staging/dotty that referenced this issue Sep 28, 2017
odersky added a commit that referenced this issue Sep 29, 2017
Fix #3161: Check that operands of &, | are simple-kinded
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

3 participants