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

StackOverflowError calculating LUBs #7612

Closed
scabug opened this issue Jun 26, 2013 · 10 comments
Closed

StackOverflowError calculating LUBs #7612

scabug opened this issue Jun 26, 2013 · 10 comments

Comments

@scabug
Copy link

scabug commented Jun 26, 2013

Originally Reported: https://groups.google.com/d/msg/scala-internals/itLkThK-yOY/fcTP1ePkNkgJ

Regressed in scala/scala@a06d31f

tail build.sbt test.scala
==> build.sbt <==
scalaVersion := "2.10.2"

libraryDependencies += "net.liftweb" %% "lift-mapper" % "2.5"

==> test.scala <==

class B extends LongKeyedMapper[B] with IdPK {
  def getSingleton = B
}

object B extends B with LongKeyedMetaMapper[B]

object Test {
  def foo(a: A, b: B) = if (true) a else b // LUB triggers StackOverflowError
}

sbt -scala-home `scala-hash -h f3cdf146709~3`  compile
[info] f3cdf14670 => /Users/jason/usr/scala-v2.10.0-460-ga06d31f
Detected sbt version 0.12.1
Using /Users/jason/.sbt/0.12.1 as sbt dir, -sbt-dir to override.
[info] Loading global plugins from /Users/jason/.sbt/0.12.1/plugins
[info] Set current project to default-3d6815 (in build file:/Users/jason/code/scratch3/)
[info] Defining {.}/*:scala-home
[info] The new value will be used by no settings or tasks.
[info] Reapplying settings...
[info] Set current project to default-3d6815 (in build file:/Users/jason/code/scratch3/)
[info] Compiling 1 Scala source to /Users/jason/code/scratch3/target/scala-2.10/classes...
[error]
[error]      while compiling: /Users/jason/code/scratch3/test.scala
[error]         during phase: typer

...
java.lang.StackOverflowError
        at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4160)
        at scala.reflect.internal.Types$typeVarToOriginMap$.apply(Types.scala:4886)
        at scala.reflect.internal.Types$typeVarToOriginMap$.apply(Types.scala:4883)
        at scala.collection.immutable.List.loop$1(List.scala:164)
        at scala.collection.immutable.List.mapConserve(List.scala:180)
        at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4202)
        at scala.reflect.internal.Types$typeVarToOriginMap$.apply(Types.scala:4886)
        at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4193)
        at scala.reflect.internal.Types$typeVarToOriginMap$.apply(Types.scala:4886)
        at scala.reflect.internal.Types$TypeMap$$anonfun$noChangeToSymbols$1.apply(Types.scala:4257)
        at scala.reflect.internal.Types$TypeMap$$anonfun$noChangeToSymbols$1.apply(Types.scala:4257)
        at scala.collection.LinearSeqOptimized$class.forall(LinearSeqOptimized.scala:70)
        at scala.collection.immutable.List.forall(List.scala:78)
        at scala.reflect.internal.Types$TypeMap.noChangeToSymbols(Types.scala:4257)
        at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4270)
        at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4208)
        at scala.reflect.internal.Types$typeVarToOriginMap$.apply(Types.scala:4886)
        at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4194)
        at scala.reflect.internal.Types$typeVarToOriginMap$.apply(Types.scala:4886)
        at scala.reflect.internal.Types$TypeMap$$anonfun$noChangeToSymbols$1.apply(Types.scala:4257)
        at scala.reflect.internal.Types$TypeMap$$anonfun$noChangeToSymbols$1.apply(Types.scala:4257)
        at scala.collection.LinearSeqOptimized$class.forall(LinearSeqOptimized.scala:70)
        at scala.collection.immutable.List.forall(List.scala:78)
        at scala.reflect.internal.Types$TypeMap.noChangeToSymbols(Types.scala:4257)
        at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4270)
        at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4208)
        at scala.reflect.internal.Types$typeVarToOriginMap$.apply(Types.scala:4886)
        at scala.reflect.internal.Types$typeVarToOriginMap$.apply(Types.scala:4883)
        at scala.collection.immutable.List.loop$1(List.scala:164)
        at scala.collection.immutable.List.mapConserve(List.scala:180)
        at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4202)
        at scala.reflect.internal.Types$typeVarToOriginMap$.apply(Types.scala:4886)
        at scala.reflect.internal.Types$Type.isGround(Types.scala:1050)
        at scala.reflect.internal.Types$SubTypePair.scala$reflect$internal$Types$SubTypePair$$suspend$1(Types.scala:5158)
        at scala.reflect.internal.Types$SubTypePair$$anonfun$45.apply(Types.scala:5162)
        at scala.reflect.internal.Types$SubTypePair$$anonfun$45.apply(Types.scala:5162)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:119)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
        at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:119)
        at scala.reflect.internal.Types$SubTypePair.equals(Types.scala:5162)
        at scala.collection.mutable.FlatHashTable$class.findEntryImpl(FlatHashTable.scala:125)
        at scala.collection.mutable.FlatHashTable$class.containsEntry(FlatHashTable.scala:119)
        at scala.collection.mutable.HashSet.containsEntry(HashSet.scala:41)
        at scala.collection.mutable.HashSet.contains(HashSet.scala:58)
        at scala.collection.GenSetLike$class.apply(GenSetLike.scala:43)
        at scala.collection.mutable.AbstractSet.apply(Set.scala:45)
        at scala.reflect.internal.Types$class.isSubType(Types.scala:5734)
        at scala.reflect.internal.SymbolTable.isSubType(SymbolTable.scala:13)
        at scala.reflect.internal.Types$$anonfun$59.apply(Types.scala:6605)
        at scala.reflect.internal.Types$$anonfun$59.apply(Types.scala:6605)
        at scala.collection.TraversableLike$$anonfun$filter$1.apply(TraversableLike.scala:264)
        at scala.collection.immutable.List.foreach(List.scala:312)
        at scala.collection.TraversableLike$class.filter(TraversableLike.scala:263)
        at scala.collection.AbstractTraversable.filter(Traversable.scala:105)
        at scala.reflect.internal.Types$class.elimSub0$1(Types.scala:6605)
        at scala.reflect.internal.Types$class.elimSub(Types.scala:6608)
        at scala.reflect.internal.Types$class.loop$2(Types.scala:6532)
        at scala.reflect.internal.Types$class.loop$2(Types.scala:6533)
        at scala.reflect.internal.Types$class.loop$2(Types.scala:6533)
        at scala.reflect.internal.Types$class.loop$2(Types.scala:6533)
        at scala.reflect.internal.Types$class.loop$2(Types.scala:6533)
        at scala.reflect.internal.Types$class.loop$2(Types.scala:6533)
        at scala.reflect.internal.Types$class.loop$2(Types.scala:6533)
        at scala.reflect.internal.Types$class.loop$2(Types.scala:6533)
        at scala.reflect.internal.Types$class.lubList(Types.scala:6560)
        at scala.reflect.internal.Types$class.lub1$1(Types.scala:6743)
        at scala.reflect.internal.Types$class.lub0$1(Types.scala:6736)
        at scala.reflect.internal.Types$class.lub0$1(Types.scala:6725)
        at scala.reflect.internal.Types$class.scala$reflect$internal$Types$$lub(Types.scala:6831)
        at scala.reflect.internal.Types$class.lubsym$1(Types.scala:6770)
        at scala.reflect.internal.Types$$anonfun$69.apply(Types.scala:6792)
        at scala.reflect.internal.Types$$anonfun$69.apply(Types.scala:6790)
        at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
        at scala.reflect.internal.Scopes$Scope.foreach(Scopes.scala:315)
        at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
        at scala.reflect.internal.Types$class.lub1$1(Types.scala:6790)
        at scala.reflect.internal.Types$class.lub0$1(Types.scala:6736)
        at scala.reflect.internal.Types$class.scala$reflect$internal$Types$$lub(Types.scala:6831)
        at scala.reflect.internal.Types$$anonfun$85.apply(Types.scala:7058)
        at scala.reflect.internal.Types$$anonfun$85.apply(Types.scala:7041)
        at scala.reflect.internal.util.Collections$class.map2(Collections.scala:51)
        at scala.reflect.internal.SymbolTable.map2(SymbolTable.scala:13)
        at scala.reflect.internal.Types$class.mergePrefixAndArgs(Types.scala:7041)
        at scala.reflect.internal.SymbolTable.mergePrefixAndArgs(SymbolTable.scala:13)
        at scala.reflect.internal.Types$class.loop$2(Types.scala:6532)
        at scala.reflect.internal.Types$class.lubList(Types.scala:6560)
        at scala.reflect.internal.Types$class.lub1$1(Types.scala:6743)
        at scala.reflect.internal.Types$class.lub0$1(Types.scala:6736)
        at scala.reflect.internal.Types$class.scala$reflect$internal$Types$$lub(Types.scala:6831)
        at scala.reflect.internal.Types$class.solveOne$1(Types.scala:6401)
        at scala.reflect.internal.Types$$anonfun$solve$1.apply(Types.scala:6411)
        at scala.reflect.internal.Types$$anonfun$solve$1.apply(Types.scala:6411)
        at scala.reflect.internal.util.Collections$class.foreach3(Collections.scala:160)
        at scala.reflect.internal.SymbolTable.foreach3(SymbolTable.scala:13)
        at scala.reflect.internal.Types$class.solve(Types.scala:6411)
        at scala.reflect.internal.SymbolTable.solve(SymbolTable.scala:13)
        at scala.reflect.internal.Types$ExistentialType.withTypeVars(Types.scala:2842)
        at scala.reflect.internal.Types$class.thirdTry$1(Types.scala:6057)
        at scala.reflect.internal.Types$class.secondTry$1(Types.scala:6016)
        at scala.reflect.internal.Types$class.firstTry$1(Types.scala:5992)
        at scala.reflect.internal.Types$class.isSubType2(Types.scala:6135)
        at scala.reflect.internal.Types$class.isSubType(Types.scala:5739)
        at scala.reflect.internal.SymbolTable.isSubType(SymbolTable.scala:13)
        at scala.reflect.internal.Types$class.thirdTry$1(Types.scala:6077)
        at scala.reflect.internal.Types$class.secondTry$1(Types.scala:6016)
        at scala.reflect.internal.Types$class.firstTry$1(Types.scala:5992)
        at scala.reflect.internal.Types$class.isSubType2(Types.scala:6135)
        at scala.reflect.internal.Types$class.isSubType(Types.scala:5739)
        at scala.reflect.internal.SymbolTable.isSubType(SymbolTable.scala:13)
        at scala.reflect.internal.Types$class.scala$reflect$internal$Types$$specializesSym(Types.scala:6176)
        at scala.reflect.internal.Types$class.specializedBy$1(Types.scala:6159)
        at scala.reflect.internal.Types$class.specializesSym(Types.scala:6163)
        at scala.reflect.internal.SymbolTable.specializesSym(SymbolTable.scala:13)
        at scala.reflect.internal.Types$$anonfun$thirdTry$1$2.apply(Types.scala:6055)
        at scala.reflect.internal.Types$$anonfun$thirdTry$1$2.apply(Types.scala:6055)
        at scala.collection.Iterator$class.forall(Iterator.scala:739)
        at scala.collection.AbstractIterator.forall(Iterator.scala:1157)
        at scala.collection.IterableLike$class.forall(IterableLike.scala:75)
        at scala.reflect.internal.Scopes$Scope.forall(Scopes.scala:44)
        at scala.reflect.internal.Types$class.thirdTry$1(Types.scala:6055)
        at scala.reflect.internal.Types$class.secondTry$1(Types.scala:6016)
        at scala.reflect.internal.Types$class.firstTry$1(Types.scala:5992)
        at scala.reflect.internal.Types$class.isSubType2(Types.scala:6135)
        at scala.reflect.internal.Types$class.isSubType(Types.scala:5739)
        at scala.reflect.internal.SymbolTable.isSubType(SymbolTable.scala:13)
        at scala.reflect.internal.Types$$anonfun$70.apply(Types.scala:6805)
        at scala.reflect.internal.Types$$anonfun$70.apply(Types.scala:6804)
        at scala.collection.LinearSeqOptimized$class.forall(LinearSeqOptimized.scala:70)
        at scala.collection.immutable.List.forall(List.scala:78)
        at scala.reflect.internal.Types$class.lub1$1(Types.scala:6804)
        at scala.reflect.internal.Types$class.lub0$1(Types.scala:6736)
        at scala.reflect.internal.Types$class.scala$reflect$internal$Types$$lub(Types.scala:6831)
        at scala.reflect.internal.Types$class.solveOne$1(Types.scala:6401)
        at scala.reflect.internal.Types$$anonfun$solve$1.apply(Types.scala:6411)
        at scala.reflect.internal.Types$$anonfun$solve$1.apply(Types.scala:6411)
        at scala.reflect.internal.util.Collections$class.foreach3(Collections.scala:160)
        at scala.reflect.internal.SymbolTable.foreach3(SymbolTable.scala:13)
        at scala.reflect.internal.Types$class.solve(Types.scala:6411)
        at scala.reflect.internal.SymbolTable.solve(SymbolTable.scala:13)
        at scala.reflect.internal.Types$ExistentialType.withTypeVars(Types.scala:2842)
        at scala.reflect.internal.Types$class.thirdTry$1(Types.scala:6057)
        at scala.reflect.internal.Types$class.secondTry$1(Types.scala:6016)
        at scala.reflect.internal.Types$class.firstTry$1(Types.scala:5992)
        at scala.reflect.internal.Types$class.isSubType2(Types.scala:6135)
        at scala.reflect.internal.Types$class.isSubType(Types.scala:5739)
        at scala.reflect.internal.SymbolTable.isSubType(SymbolTable.scala:13)
...
@scabug
Copy link
Author

scabug commented Jun 26, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7612?orig=1
Reporter: @retronym
Affected Versions: 2.10.1

@scabug
Copy link
Author

scabug commented Jun 26, 2013

@retronym said:
The particular change responsible is:

-      val ts1 = ts0 mapConserve (t => elimAnonymousClass(t.underlying))
+      val ts1 = ts0 mapConserve (t => elimAnonymousClass(t.dealiasWiden))

scala/scala@a06d31f6a#L0L6621

@scabug
Copy link
Author

scabug commented Jun 26, 2013

@retronym said:
Here's a standalone test case:

trait BaseMapper  {
  type M
  def primaryKeyField: MappedField[M]
}

trait Mapper[A] extends BaseMapper {
  type M = A
}

trait IdPK {
  self: BaseMapper =>
  object id extends MappedField[M]
}

trait KeyedMapper[A]
  extends Mapper[A] with BaseMapper

trait MappedField[A]

abstract class A extends KeyedMapper[A] {
  def primaryKeyField: MappedField[A]
}

abstract class B extends Mapper[B] with BaseMapper with IdPK {
  // okay
  // def primaryKeyField: MappedField[M]

  // SOE
  def primaryKeyField: id.type
}

object Test {
  def foo(a: A, b: B) = if (true) a else b // LUB triggers StackOverflowError
}

@scabug
Copy link
Author

scabug commented Jun 26, 2013

@retronym said:
WIP: retronym/scala@scala:2.10.x...ticket/7621
Suggested workaround for Lift: lift/framework#1465

@scabug
Copy link
Author

scabug commented Jun 27, 2013

@retronym said:
scala/scala#2685

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@adriaanm said:
Since 2.11.0-RC1 is one week away, pushing all non-blockers without PR to 2.11.1-RC1. Please undo the change if I missed work in progress.

@scabug
Copy link
Author

scabug commented Aug 5, 2014

@gkossakowski said:
The 2.11.2 is out so I'm rescheduling the issue for 2.11.3.

@scabug
Copy link
Author

scabug commented Nov 4, 2014

@retronym said:
Updating fix-by version to 2.11.5.

@diesalbla
Copy link

diesalbla commented Sep 22, 2018

Playing with the example, I have reduced it (and renamed it) to the following test case, which has neither abstract classes, nor type members, nor self-annotations, but still throws a similar Stack Overflow error:

trait Fili[A]
trait Kili[M] {
  def fili: Fili[M]
}
trait A extends Kili[A] {
  def fili: Fili[A]
}
trait Ori[M] extends Kili[M] {
  val ori: Fili[M]
  def fili: ori.type
}
trait B extends Ori[B]

object Test {
  def foo(a: A, b: B) = if (true) a else b // LUB triggers StackOverflowError
}

Applying the following changes make this code to compile:

  • Removing the type parameter from the Fili trait.
  • Removing the declaration of method fili from trait Kili.
  • Removing the re-declaration of method fili from trait A.
  • Expanding the elements of trait Ori inside trait B.
  • Replacing the body of method foo with if (true) then a.fili else b.fili.

The StackOverflow error is due to an infinite recursion between

joroKr21 added a commit to joroKr21/scala that referenced this issue Sep 30, 2018
@joroKr21
Copy link
Member

Making Fili covariant also avoids the SO.

joroKr21 added a commit to joroKr21/scala that referenced this issue Oct 1, 2018
joroKr21 added a commit to joroKr21/scala that referenced this issue Oct 2, 2018
The comment about higher-order type parameters shoud not apply anymore.

Fixes scala/bug#7612
joroKr21 added a commit to joroKr21/scala that referenced this issue Oct 3, 2018
@SethTisue SethTisue assigned joroKr21 and unassigned retronym Jan 8, 2019
@SethTisue SethTisue modified the milestones: Backlog, 2.13.0-RC1 Jan 8, 2019
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

6 participants