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

Internal compiler error about lub/glb #4090

Closed
scabug opened this issue Dec 16, 2010 · 6 comments
Closed

Internal compiler error about lub/glb #4090

scabug opened this issue Dec 16, 2010 · 6 comments

Comments

@scabug
Copy link

scabug commented Dec 16, 2010

=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===
run the following code with "scala script.scala":

trait Foo[TC[_], U] {
  def map[V](f: U => V): TC[V]
}

implicit def listFoo[A](v: List[A]): Foo[List, A] = new Foo[List, A] {
  def map[V](f: (A) => V) = v map f
}

def mapping[V, T[_], U <: T[V] <% Foo[T, V], R](value: Foo[T, V], f: V => R): T[R] = value.map(f)
mapping(List(1,2,3), _ + 1)  // <-- ERROR here

def mapping2[V, T[_], U <: T[_] <% Foo[T, V], R](value: Foo[T, V], f: V => R): T[R] = value.map(f)
println(mapping2(List(1,2,3), _ + 1)) // <-- no internal compiler error, but type inference won't work

mapping[Int, List, List[Int], Int](List(1,2,3), _ + 1) // <-- compiles
mapping2[Int, List, List[Int], Int](List(1,2,3), _ + 1) // <-- compiles

=== What is the expected behavior? ===
No exception from the compiler and better type inference if possible.

=== What do you see instead? ===
The compiler throws a java.lang.Error with the error message "trying to do lub/glb of typevar ?U".

The stacktrace is:

java.lang.Error: trying to do lub/glb of typevar ?U
	at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:33)
	at scala.tools.nsc.symtab.Types$$class.stripType$$1(Types.scala:5024)
	at scala.tools.nsc.symtab.Types$$$$anonfun$$32.apply(Types.scala:5027)
	at scala.tools.nsc.symtab.Types$$$$anonfun$$32.apply(Types.scala:5027)
	at scala.collection.immutable.List.loop$$1(List.scala:119)
	at scala.collection.immutable.List.mapConserve(List.scala:135)
	at scala.tools.nsc.symtab.Types$$class.stripExistentialsAndTypeVars(Types.scala:5027)
	at scala.tools.nsc.symtab.Types$$class.lub1$$1(Types.scala:5120)
	at scala.tools.nsc.symtab.Types$$class.lub0$$1(Types.scala:5114)
	at scala.tools.nsc.symtab.Types$$class.lub(Types.scala:5184)
	at scala.tools.nsc.symtab.SymbolTable.lub(SymbolTable.scala:13)
	at scala.tools.nsc.symtab.Types$$class.solveOne$$1(Types.scala:4897)
	at scala.tools.nsc.symtab.Types$$$$anonfun$$solve$$2.apply(Types.scala:4906)
	at scala.tools.nsc.symtab.Types$$$$anonfun$$solve$$2.apply(Types.scala:4905)
	at scala.collection.LinearSeqOptimized$$class.foreach(LinearSeqOptimized.scala:61)
	at scala.collection.immutable.List.foreach(List.scala:45)
	at scala.tools.nsc.symtab.Types$$class.solve(Types.scala:4905)
	at scala.tools.nsc.symtab.SymbolTable.solve(SymbolTable.scala:13)
	at scala.tools.nsc.typechecker.Infer$$class.solvedTypes(Infer.scala:141)
	at scala.tools.nsc.Global$$analyzer$$.solvedTypes(Global.scala:350)
	at scala.tools.nsc.typechecker.Infer$$Inferencer.methTypeArgs(Infer.scala:663)
	at scala.tools.nsc.typechecker.Infer$$Inferencer.inferMethodInstance(Infer.scala:1162)
	at scala.tools.nsc.typechecker.Typers$$Typer.doTypedApply(Typers.scala:2507)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedApply$$1(Typers.scala:3350)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:4037)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4192)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedStat$$1(Typers.scala:2121)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2204)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2204)
	at scala.collection.immutable.List.loop$$1(List.scala:119)
	at scala.collection.immutable.List.mapConserve(List.scala:135)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedStats(Typers.scala:2204)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedTemplate(Typers.scala:1550)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedClassDef(Typers.scala:1311)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3843)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4192)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedStat$$1(Typers.scala:2121)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2204)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2204)
	at scala.collection.immutable.List.loop$$1(List.scala:119)
	at scala.collection.immutable.List.mapConserve(List.scala:135)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedStats(Typers.scala:2204)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedBlock(Typers.scala:1954)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3884)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4192)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedBlock(Typers.scala:1955)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3884)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4192)
	at scala.tools.nsc.typechecker.Typers$$Typer.transformedOrTyped(Typers.scala:4337)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedDefDef(Typers.scala:1788)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3852)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4192)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedStat$$1(Typers.scala:2121)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2204)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2204)
	at scala.collection.immutable.List.loop$$1(List.scala:119)
	at scala.collection.immutable.List.mapConserve(List.scala:135)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedStats(Typers.scala:2204)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedTemplate(Typers.scala:1550)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedModuleDef(Typers.scala:1353)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3846)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4192)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedStat$$1(Typers.scala:2121)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2204)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2204)
	at scala.collection.immutable.List.loop$$1(List.scala:119)
	at scala.collection.immutable.List.mapConserve(List.scala:135)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedStats(Typers.scala:2204)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3839)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4192)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4241)
	at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$3.apply(Analyzer.scala:87)
	at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply(Global.scala:330)
	at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply(Global.scala:330)
	at scala.tools.nsc.reporters.Reporter.withSource(Reporter.scala:48)
	at scala.tools.nsc.Global$$GlobalPhase.applyPhase(Global.scala:330)
	at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$3$$$$anonfun$$run$$1.apply(Analyzer.scala:82)
	at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$3$$$$anonfun$$run$$1.apply(Analyzer.scala:82)
	at scala.collection.Iterator$$class.foreach(Iterator.scala:633)
	at scala.collection.mutable.ListBuffer$$$$anon$$1.foreach(ListBuffer.scala:311)
	at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$3.run(Analyzer.scala:82)
	at scala.tools.nsc.Global$$Run.compileSources(Global.scala:863)
	at scala.tools.nsc.Global$$Run.compile(Global.scala:943)
	at scala.tools.nsc.StandardCompileServer.session(CompileServer.scala:123)
	at scala.tools.util.SocketServer$$$$anonfun$$doSession$$1.apply(SocketServer.scala:69)
	at scala.tools.util.SocketServer$$$$anonfun$$doSession$$1.apply(SocketServer.scala:69)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
	at scala.Console$$.withOut(Console.scala:99)
	at scala.tools.util.SocketServer.doSession(SocketServer.scala:69)
	at scala.tools.util.SocketServer.run(SocketServer.scala:88)
	at scala.tools.nsc.StandardCompileServer.main(CompileServer.scala:155)
	at scala.tools.nsc.CompileServer.main(CompileServer.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at scala.tools.nsc.util.ScalaClassLoader$$$$anonfun$$run$$1.apply(ScalaClassLoader.scala:81)
	at scala.tools.nsc.util.ScalaClassLoader$$class.asContext(ScalaClassLoader.scala:24)
	at scala.tools.nsc.util.ScalaClassLoader$$URLClassLoader.asContext(ScalaClassLoader.scala:91)
	at scala.tools.nsc.util.ScalaClassLoader$$class.run(ScalaClassLoader.scala:81)
	at scala.tools.nsc.util.ScalaClassLoader$$URLClassLoader.run(ScalaClassLoader.scala:91)
	at scala.tools.nsc.ObjectRunner$$.run(ObjectRunner.scala:33)
	at scala.tools.nsc.ObjectRunner$$.runAndCatch(ObjectRunner.scala:40)
	at scala.tools.nsc.MainGenericRunner$$.process(MainGenericRunner.scala:89)
	at scala.tools.nsc.MainGenericRunner$$.main(MainGenericRunner.scala:33)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
error: fatal error (server aborted): trying to do lub/glb of typevar ?U
two errors found

=== What versions of the following are you using? ===

  • Scala: 2.8.1.final and 2.9.0.r23778-b20101216020130
  • Java: java version "1.6.0_22", Java(TM) SE Runtime Environment (build 1.6.0_22-b04), Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
  • Operating system: Linux titan 2.6.35-23-generic SI-41-Ubuntu SMP Wed Nov 24 11:55:36 UTC 2010 x86_64 GNU/Linux
@scabug
Copy link
Author

scabug commented Dec 16, 2010

Imported From: https://issues.scala-lang.org/browse/SI-4090?orig=1
Reporter: Rico Schiekel (fire)

@scabug
Copy link
Author

scabug commented Jun 25, 2011

@paulp said:
This doesn't crash anymore, and we have plenty of other tickets asking for better type inference.

@scabug
Copy link
Author

scabug commented Aug 29, 2011

@milessabin said:
Actually, this does still crash, on the call "mapping(List(1,2,3), _ + 1)" where the error is indicated in the original submission.

@scabug
Copy link
Author

scabug commented Aug 29, 2011

@milessabin said:
Seeing as this wasn't actually fixed, #4949 is actually a duplicate of this, so the example there can serve as a more reduced case for this one,

object Bug {
  trait H[F[_]]
  def f[F[_], T, FT <: F[T]](h : H[F]) = 1
  f(new H[Set]{})
}

Which results in the following stacktrace (2.9.0-1, 2.9.1.RC4 and trunk),

error: java.lang.Error: trying to do lub/glb of typevar ?FT
        at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:32)
        at scala.reflect.internal.Types$class.stripType$1(Types.scala:5438)
        at scala.reflect.internal.Types$$anonfun$44.apply(Types.scala:5441)
        at scala.reflect.internal.Types$$anonfun$44.apply(Types.scala:5441)
        at scala.collection.immutable.List.loop$1(List.scala:150)
        at scala.collection.immutable.List.mapConserve(List.scala:166)
        at scala.reflect.internal.Types$class.stripExistentialsAndTypeVars(Types.scala:5441)
        at scala.reflect.internal.Types$class.lub1$1(Types.scala:5536)
        at scala.reflect.internal.Types$class.lub0$1(Types.scala:5530)
        at scala.reflect.internal.Types$class.lub(Types.scala:5615)
        at scala.reflect.internal.SymbolTable.lub(SymbolTable.scala:12)
        at scala.reflect.internal.Types$class.solveOne$1(Types.scala:5222)
        at scala.reflect.internal.Types$$anonfun$solve$2.apply(Types.scala:5231)
        at scala.reflect.internal.Types$$anonfun$solve$2.apply(Types.scala:5230)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:77)
        at scala.reflect.internal.Types$class.solve(Types.scala:5230)
        at scala.reflect.internal.SymbolTable.solve(SymbolTable.scala:12)
        at scala.tools.nsc.typechecker.Infer$class.solvedTypes(Infer.scala:142)
        at scala.tools.nsc.Global$analyzer$.solvedTypes(Global.scala:381)
        at scala.tools.nsc.typechecker.Infer$Inferencer.methTypeArgs(Infer.scala:728)
        at scala.tools.nsc.typechecker.Infer$Inferencer.inferMethodInstance(Infer.scala:1269)
        at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:2558)
        at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:3438)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4174)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4329)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2162)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2246)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2246)
        at scala.collection.immutable.List.loop$1(List.scala:150)
        at scala.collection.immutable.List.mapConserve(List.scala:166)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2246)
        at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1567)
        at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1375)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3983)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4329)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2162)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2246)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2246)
        at scala.collection.immutable.List.loop$1(List.scala:150)
        at scala.collection.immutable.List.mapConserve(List.scala:166)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2246)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3976)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4329)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4388)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:94)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:359)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:86)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:86)
        at scala.collection.Iterator$class.foreach(Iterator.scala:583)
        at scala.collection.mutable.ListBuffer$$anon$1.foreach(ListBuffer.scala:316)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:86)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:1013)
        at scala.tools.nsc.Global$Run.compile(Global.scala:1101)
        at scala.tools.nsc.Driver.doCompile(Driver.scala:31)
        at scala.tools.nsc.Main$.doCompile(Main.scala:81)
        at scala.tools.nsc.Driver.process(Driver.scala:52)
        at scala.tools.nsc.Driver.main(Driver.scala:65)
        at scala.tools.nsc.Main.main(Main.scala)

@scabug
Copy link
Author

scabug commented Aug 30, 2011

@paulp said:
Bug still exists and no test case checked in? Sorry about that.

@scabug
Copy link
Author

scabug commented Jan 5, 2013

@paulp said:
Going to unfairly (in terms of which is the dup) close this as a duplicate of #5559.

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

2 participants