Skip to content
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

Types$$TypeRef Types$$SubType stack overflow #13

Closed
scabug opened this issue Aug 28, 2007 · 9 comments
Closed

Types$$TypeRef Types$$SubType stack overflow #13

scabug opened this issue Aug 28, 2007 · 9 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Aug 28, 2007

== 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

@scabug
Copy link
Author

scabug commented Aug 28, 2007

Imported From: https://issues.scala-lang.org/browse/SI-13?orig=1
Reporter: @michelou

@scabug
Copy link
Author

scabug commented Aug 29, 2007

@dubochet said:
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)) } [st�phane]

@scabug
Copy link
Author

scabug commented Aug 29, 2007

@dubochet said:
The example now causes a type error:

bug1279a.scala:34: error: no type parameters for method all4ImplSI-4259: (MSI-3759{type TSI-4288 <: USI-4285})StreamSI-437[MSI-3759{type TSI-4291 <: USI-4285}] exist so that it can be applied to arguments (firstSI-4262.selfTypeSI-3770)
 --- because ---
result type StreamSI-437[MSI-3759{type TSI-4291 <: USI-4285}] is incompatible with expected type StreamSI-437[MSI-3759{type TSI-4264 <: USI-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.

[martin]

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone postponed deleted

@scabug
Copy link
Author

scabug commented Aug 12, 2009

@paulp said:
The example given in the ticket compiles with trunk. The shorter example doesn't, but I think the reason is unrelated.

abstract class M { 
  type T 
  def all4Impl[U](first: M { type T <: U }): Stream[M { type T <: U }] =
    Stream.cons(first, all4Impl(Stream.empty))
}

@scabug
Copy link
Author

scabug commented Jul 2, 2010

@paulp said:
(In r22467) Test cases close #13, #95. No review.

(That's right, multiple two digit tickets.)

@scabug
Copy link
Author

scabug commented Sep 16, 2010

@adriaanm said:
see test/files/pos/bug1279a.scala (and r23011)

@scabug
Copy link
Author

scabug commented Apr 26, 2011

@soc said (edited on May 4, 2012 1:59:57 AM UTC):
With Scala version 2.10.0-20120430-094203-cfd037271e (OpenJDK 64-Bit Server VM, Java 1.6.0_24) in file test/files/pos/bug1279a.scala:

// TODO!!! fix this bug for real, it compiles successfully, but weird types are inferred
    def all4Impl[U](first: M {type T <: U}): Stream[M {type T <: U}] = Stream.cons(first, all4Impl(first.next))

results in

<console>:34: error: type mismatch;
 found   : first.selfType
    (which expands to)  M{type T <: first.T}
 required: M{type T <: Nothing}
           def all4Impl[U](first: M {type T <: U}): Stream[M {type T <: U}] = Stream.cons(first, all4Impl(first.next))
                                                                                                                ^

Does this change the status of the bug?

@scabug
Copy link
Author

scabug commented May 4, 2012

@paulp said:
Nope. I updated the test to make clearer what should happen. bbdd570ccc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants