Skip to content

Failure with path-dependent function values, asSeenFrom stress-tests and type inference #4906

Closed
@Blaisorblade

Description

@Blaisorblade

While playing with #4884 and #4902 I run into the following crasher. v2 is fine, but functions from v3 onward crash. Using methods works around the issue, so this can be handled independently from #4884.

object Test {
  trait A
  trait TestConstructor1 { type F[_ <: A] }
  trait TestConstructor2[D] {
    type F[_ <: D]
    class G[X <: D]
    trait TestConstructor3[E] {
      type G[_ <: D & E]
      class H[X <: D & E]
    }
  }

  val v1: TestConstructor1 => Unit = { f =>
    type P[a <: A] = f.F[a] // OK
  }

  val v2: TestConstructor2[A] => Unit = { f =>
    type P[a <: A] = f.F[a] // Error! Type argument a does not conform to upper bound D
  }

  def f2(f: TestConstructor2[A]): Unit = {
    type P[a <: A] = f.F[a] // Error! Type argument a does not conform to upper bound D
  }

  val v3: (f: TestConstructor2[A]) => (g: f.TestConstructor3[A]) => Unit = ??? // ok
  val v4: (f: TestConstructor2[A]) => (g: f.TestConstructor3[A]) => Unit = {f => ???} // crash
  // val v5: (f: TestConstructor2[A]) => (g: f.TestConstructor3[A]) => Unit = {(f: TestConstructor2[A]) => ???} // crash
  // val v6: (f: TestConstructor2[A]) => (g: f.TestConstructor3[A]) => Unit = {(f: TestConstructor2[A]) => (g: f.TestConstructor3[A]) => ???} // crash
                                                                                                                                           // val v3: (f: TestConstructor2[A]) => (g: f.TestConstructor3[A]) => Unit = { f => g =>
                                                                                                                                           //   type P[a <: A] = f.F[a] // Error! Type argument a does not conform to upper bound D
                                                                                                                                           //   // type Q[a <: A] = g.G[a]
                                                                                                                                           //   // type R[a <: A] = (f.F & g.G)[a]
                                                                                                                                           //   // type R[a <: A] = ([X] => f.F[X] & g.G[X])[a]
                                                                                                                                           // }
  def f3(f: TestConstructor2[A], g: f.TestConstructor3[A]): Unit = {
    type P[a <: A] = f.F[a] // Error! Type argument a does not conform to upper bound D
    type Q[a <: A] = g.G[a]
    // type R[a <: A] = (f.F & g.G)[a] // compiler error
    type R[a <: A] = ([X <: A] => f.F[X] & g.G[X])[a]
    type S[a <: A] = f.G[a] & g.H[a]
  }
}
sbt:dotty> dotc -d out mytmp/i4884a.scala
[warn] Multiple main classes detected.  Run 'show discoveredMainClasses' to see the list
[info] Running (fork) dotty.tools.dotc.Main -classpath /Users/pgiarrusso/git/dotty/library/../out/bootstrap/dotty-library-bootstrapped/scala-0.10/dotty-library_0.10-0.10.0-bin-SNAPSHOT.jar -d out mytmp/i4884a.scala
exception occurred while typechecking mytmp/i4884a.scala
exception occurred while compiling mytmp/i4884a.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: (g: Nothing): Unit & (g: v1.TestConstructor3[Test.A]): Unit / MethodType(List(g), List(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing)), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),module scala),class Unit)) & MethodType(List(g), List(AppliedType(TypeRef(TermParamRef(v1),class TestConstructor3),List(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),module class Test$)),class A)))), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),module scala),class Unit))
	at scala.Predef$.assert(Predef.scala:219)
	at dotty.tools.dotc.core.Types$AndType$.apply(Types.scala:2515)
	at dotty.tools.dotc.core.TypeComparer.$anonfun$andType$3(TypeComparer.scala:1485)
	at dotty.tools.dotc.core.TypeComparer.liftIfHK(TypeComparer.scala:1523)
	at dotty.tools.dotc.core.TypeComparer.$anonfun$andType$2(TypeComparer.scala:1485)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.core.TypeComparer.andType(TypeComparer.scala:1478)
	at dotty.tools.dotc.core.TypeComparer.$anonfun$glb$2(TypeComparer.scala:1302)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.core.TypeComparer.glb(TypeComparer.scala:1268)
	at dotty.tools.dotc.core.Types$Type.$anonfun$$amp$1(Types.scala:893)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.core.Types$Type.$amp(Types.scala:893)
	at dotty.tools.dotc.core.TypeComparer.distributeAnd(TypeComparer.scala:1561)
	at dotty.tools.dotc.core.TypeComparer.$anonfun$andType$2(TypeComparer.scala:1479)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.core.TypeComparer.andType(TypeComparer.scala:1478)
	at dotty.tools.dotc.core.TypeComparer.$anonfun$glb$2(TypeComparer.scala:1302)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.core.TypeComparer.glb(TypeComparer.scala:1268)
	at dotty.tools.dotc.core.Types$Type.$anonfun$$amp$1(Types.scala:893)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.core.Types$Type.$amp(Types.scala:893)
	at dotty.tools.dotc.core.Denotations$Denotation.infoMeet$1(Denotations.scala:444)
	at dotty.tools.dotc.core.Denotations$Denotation.infoMeet$1(Denotations.scala:424)
	at dotty.tools.dotc.core.Denotations$Denotation.mergeSingleDenot$1(Denotations.scala:543)
	at dotty.tools.dotc.core.Denotations$Denotation.mergeDenot$1(Denotations.scala:460)
	at dotty.tools.dotc.core.Denotations$Denotation.$amp(Denotations.scala:566)
	at dotty.tools.dotc.core.Types$Type.goRefined$1(Types.scala:628)
	at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:550)
	at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:680)
	at dotty.tools.dotc.core.Types$Type.memberExcluding(Types.scala:517)
	at dotty.tools.dotc.core.Types$Type.$anonfun$nonPrivateMember$1(Types.scala:508)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.core.Types$Type.nonPrivateMember(Types.scala:508)
	at dotty.tools.dotc.core.Types$abstractTermNameFilter$.apply(Types.scala:4569)
	at dotty.tools.dotc.core.Types$Type.$anonfun$memberNames$1(Types.scala:709)
	at dotty.tools.dotc.core.Types$Type.$anonfun$memberNames$1$adapted(Types.scala:709)
	at scala.collection.TraversableLike.$anonfun$filterImpl$1(TraversableLike.scala:248)
	at scala.collection.immutable.Set$Set1.foreach(Set.scala:95)
	at scala.collection.TraversableLike.filterImpl(TraversableLike.scala:247)
	at scala.collection.TraversableLike.filterImpl$(TraversableLike.scala:245)
	at scala.collection.AbstractTraversable.filterImpl(Traversable.scala:104)
	at scala.collection.TraversableLike.filter(TraversableLike.scala:259)
	at scala.collection.TraversableLike.filter$(TraversableLike.scala:259)
	at scala.collection.AbstractTraversable.filter(Traversable.scala:104)
	at dotty.tools.dotc.core.Types$Type.memberNames(Types.scala:709)
	at dotty.tools.dotc.core.Types$Type.memberNames(Types.scala:711)
	at dotty.tools.dotc.core.Types$Type.memberDenots(Types.scala:725)
	at dotty.tools.dotc.core.Types$Type.$anonfun$abstractTermMembers$1(Types.scala:731)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.core.Types$Type.abstractTermMembers(Types.scala:731)
	at dotty.tools.dotc.core.Types$SAMType$.unapply(Types.scala:3877)
	at dotty.tools.dotc.typer.Typer.decomposeProtoFunction(Typer.scala:742)
	at dotty.tools.dotc.typer.Typer.typedFunctionValue(Typer.scala:822)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedFunction$1(Typer.scala:757)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.typer.Typer.typedFunction(Typer.scala:756)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1827)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1869)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1900)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1896)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1912)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1976)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedBlock$1(Typer.scala:668)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:666)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1825)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1869)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1900)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1896)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1912)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1976)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedValDef$1(Typer.scala:1395)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:1389)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1803)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1868)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1900)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1896)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1912)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1931)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1965)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedClassDef$1(Typer.scala:1565)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1488)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1809)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1868)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1900)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1896)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1912)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1931)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1965)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedPackageDef$1(Typer.scala:1675)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1668)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1848)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1869)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1900)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1896)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1912)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1976)
	at dotty.tools.dotc.typer.FrontEnd.$anonfun$typeCheck$1(FrontEnd.scala:60)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:34)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:58)
	at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$6(FrontEnd.scala:88)
	at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$6$adapted(FrontEnd.scala:88)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:88)
	at dotty.tools.dotc.Run.$anonfun$compileUnits$3(Run.scala:175)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.trackTime(Stats.scala:49)
	at dotty.tools.dotc.Run.$anonfun$compileUnits$2(Run.scala:172)
	at dotty.tools.dotc.Run.$anonfun$compileUnits$2$adapted(Run.scala:170)
	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:194)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:170)
	at dotty.tools.dotc.Run.$anonfun$compileUnits$1(Run.scala:195)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:90)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:150)
	at dotty.tools.dotc.Run.compileSources(Run.scala:137)
	at dotty.tools.dotc.Run.compile(Run.scala:121)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:31)
	at dotty.tools.dotc.Driver.process(Driver.scala:134)
	at dotty.tools.dotc.Driver.process(Driver.scala:103)
	at dotty.tools.dotc.Driver.process(Driver.scala:115)
	at dotty.tools.dotc.Driver.main(Driver.scala:142)
	at dotty.tools.dotc.Main.main(Main.scala)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions