Closed
Description
I wanted to test out in DOT a way to create nominal subtyping hierarchies, that can be modular, and both sealed or open. I get a StackOverflow for the newSubCat
def.
package hello
object world extends App {
println("hello dotty!")
trait AnimalPackage {
type Animal <: AnimalU
type AnimalU = { val age: Int }
def newAnimal(a: AnimalU): Animal
def newSubAnimal[T](a: AnimalU & T): Animal & T
}
val p: AnimalPackage = new AnimalPackage { p =>
type Animal = AnimalU
override def newAnimal(a: AnimalU): Animal = a
override def newSubAnimal[T](a: AnimalU & T): Animal & T = a
}
val lambda: p.Animal = p.newAnimal(new { val age = 1 })
trait CatPackage { pc =>
type Cat <: p.Animal & pc.CatDelta
type CatDelta = { val meow: Int }
type CatU = p.AnimalU & pc.CatDelta
def newCat(c: CatU): Cat
def newSubCat[T](c: CatU & T): Cat & T
}
val pc: CatPackage = new CatPackage { pc =>
type Cat = p.Animal & pc.CatDelta
def newCat(c: CatU): Cat = p.newSubAnimal[pc.CatDelta](c)
def newSubCat[T](c: CatU & T): Cat & T = p.newSubAnimal[pc.CatDelta & T](c)
}
val felix: pc.Cat = pc.newCat(new { val age = 1; val meow = 2 })
}
The error is
[info] Running dotty.tools.dotc.Main examples/hello.scala
[error] Exception in thread "main" java.lang.StackOverflowError
[error] at dotty.tools.dotc.core.Scopes$Scope.denotsNamed(Scopes.scala:117)
[error] at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:1498)
[error] at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:1551)
[error] at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:432)
[error] at dotty.tools.dotc.core.Types$Type.goRefined$1(Types.scala:457)
[error] at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:428)
[error] at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:522)
[error] at dotty.tools.dotc.core.Denotations$Denotation.findMember(Denotations.scala:177)
[error] at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:432)
[error] at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:522)
[error] at dotty.tools.dotc.core.Denotations$Denotation.findMember(Denotations.scala:177)
[error] at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:432)
[error] at dotty.tools.dotc.core.Types$Type.goAnd$1(Types.scala:512)
[error] at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:446)
[error] at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:522)
[error] at dotty.tools.dotc.core.Denotations$Denotation.findMember(Denotations.scala:177)
[error] at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:432)
[error] at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:522)
[error] at dotty.tools.dotc.core.Types$Type.memberExcluding(Types.scala:418)
[error] at dotty.tools.dotc.core.Types$Type$$anonfun$member$1.apply(Types.scala:409)
[error] at dotty.tools.dotc.core.Types$Type$$anonfun$member$1.apply(Types.scala:409)
[error] at dotty.tools.dotc.util.Stats$.track(Stats.scala:36)
[error] at dotty.tools.dotc.core.Types$Type.member(Types.scala:408)
[error] at dotty.tools.dotc.core.Types$abstractTermNameFilter$.apply(Types.scala:3354)
[error] at dotty.tools.dotc.core.Types$Type.memberNames(Types.scala:547)
[error] at dotty.tools.dotc.core.Types$Type.memberNames(Types.scala:551)
[error] at dotty.tools.dotc.core.TypeOps$$anonfun$isVolatile$1$$anonfun$apply$1.apply(TypeOps.scala:356)
[error] at dotty.tools.dotc.core.TypeOps$$anonfun$isVolatile$1$$anonfun$apply$1.apply(TypeOps.scala:353)
[error] at scala.collection.LinearSeqOptimized$class.exists(LinearSeqOptimized.scala:93)
[error] at scala.collection.immutable.List.exists(List.scala:84)
[error] at dotty.tools.dotc.core.TypeOps$$anonfun$isVolatile$1.apply(TypeOps.scala:353)
[error] at dotty.tools.dotc.core.TypeOps$$anonfun$isVolatile$1.apply(TypeOps.scala:348)
[error] at scala.collection.LinearSeqOptimized$class.forall(LinearSeqOptimized.scala:83)
[error] at scala.collection.immutable.List.forall(List.scala:84)
[error] at dotty.tools.dotc.core.TypeOps$class.isVolatile(TypeOps.scala:348)
[error] at dotty.tools.dotc.core.Contexts$Context.isVolatile(Contexts.scala:53)
[error] at dotty.tools.dotc.core.TypeOps$$anonfun$isVolatile$1.apply(TypeOps.scala:359)
[error] at dotty.tools.dotc.core.TypeOps$$anonfun$isVolatile$1.apply(TypeOps.scala:348)
[error] at scala.collection.LinearSeqOptimized$class.forall(LinearSeqOptimized.scala:83)
[error] at scala.collection.immutable.List.forall(List.scala:84)
[error] at dotty.tools.dotc.core.TypeOps$class.isVolatile(TypeOps.scala:348)
[error] at dotty.tools.dotc.core.Contexts$Context.isVolatile(Contexts.scala:53)
[error] at dotty.tools.dotc.core.TypeOps$$anonfun$isVolatile$1.apply(TypeOps.scala:359)
[error] at dotty.tools.dotc.core.TypeOps$$anonfun$isVolatile$1.apply(TypeOps.scala:348)
[error] at scala.collection.LinearSeqOptimized$class.forall(LinearSeqOptimized.scala:83)
...