Aladdin - Scala Bugtracking
[#1279] project: compiler priority: low category: bug
submitter assigned to status date submitted
Stephane Martin moved to trac 2007-08-20 11:52:46.0
subject [contrib #753] Types$TypeRef Types$SubType stack overflow
code
// providing the type parameter in the recursive call to all4Impl
// avoids the problem


// covariant linked list
abstract class M
{ self =>

    type T
    final type selfType = M {type T <: self.T}
    type actualSelfType >: self.type <: selfType

    def next: selfType


    // I don't understand why this doesn't compile, but that's a separate matter
    // error: method all2 cannot be accessed in M.this.selfType
    // because its instance type => Stream[M{type T <: M.this.selfType#T}]
    // contains a malformed type: M.this.selfType#T
    // def all2: Stream[M {type T <: self.T}] = Stream.cons(self: actualSelfType, next.all2)


    // compiles successfully
    // def all3: Stream[M {type T <: self.T}] = all3Impl(self: actualSelfType)
    // private def all3Impl(first: M {type T <: self.T}): Stream[M {type T <: self.T}] = Stream.cons(first, all3Impl(first.next))



    def all4: Stream[M {type T <: self.T}] = Unrelated.all4Impl[T](self: actualSelfType)
}

object Unrelated
{
    def all4Impl[U](first: M {type T <: U}): Stream[M {type T <: U}] = Stream.cons(first, all4Impl(first.next))

    // compiles successfully
    // def all4Impl[U](first: M {type T <: U}): Stream[M {type T <: U}] = Stream.cons(first, all4Impl[U](first.next))
}
what happened
Exception in thread "main" java.lang.StackOverflowError
	at scala.tools.nsc.symtab.Symbols$ClassSymbol.name(Symbols.scala:1335)
	at scala.tools.nsc.symtab.Symbols$Symbol.rawInfo(Symbols.scala:502)
	at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:473)
	at scala.tools.nsc.symtab.Symbols$Symbol.closureLength$0(Symbols.scala:624)
	at scala.tools.nsc.symtab.Symbols$Symbol.isLess(Symbols.scala:627)
	at scala.tools.nsc.symtab.Types$Type.closurePos(Types.scala:528)
	at scala.tools.nsc.symtab.Symbols$Symbol.isNonBottomSubClass(Symbols.scala:643)
	at scala.tools.nsc.symtab.Types$AsSeenFromMap.toPrefix$0(Types.scala:2229)
	at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:2236)
	at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:2210)
	at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:2087)
	at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:2281)
	at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:2210)
	at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:2100)
	at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:2281)
	at scala.tools.nsc.symtab.Types$Type.asSeenFrom(Types.scala:367)
	at scala.tools.nsc.symtab.Types$Type.memberInfo(Types.scala:374)
	at scala.tools.nsc.symtab.Types$TypeRef.relativeInfo(Types.scala:1283)
	at scala.tools.nsc.symtab.Types$TypeRef.baseType(Types.scala:1396)
	at scala.tools.nsc.symtab.Types$SubType.baseType(Types.scala:710)
        [...]
what expected successful compilation
[back to overview]
Changes of this bug report
Stephane  edited on  2007-08-20 11:54:00.0
Shorter example: abstract class M { type T def all4Impl[U](first: M {type T <: U}): Stream[M {type T <: U}] = Stream.cons(first, all4Impl(Stream.empty)) }
Martin  edited on  2007-08-21 15:58:29.0
The example now causes a type error:
bug1279a.scala:34: error: no type parameters for method all4Impl#4259: (M#3759{type T#4288 <: U#4285})Stream#437[M#3759{type T#4291 <: U#4285}] exist so that it can be applied to arguments (first#4262.selfType#3770)
 --- because ---
result type Stream#437[M#3759{type T#4291 <: U#4285}] is incompatible with expected type Stream#437[M#3759{type T#4264 <: U#4261}]
    def all4Impl[U](first: M {type T <: U}): Stream[M {type T <: U}] = Stream.cons(first, all4Impl(first.next))
Not ideal, but workable. I lowered priority but leave it open.
Gilles  edited on  2007-08-29 09:58:42.0