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

lub/glb of mix of higher-kinded and raw types crashes compiler (NoCommonType in matchingBounds) #2782

Closed
scabug opened this issue Dec 9, 2009 · 7 comments
Assignees

Comments

@scabug
Copy link

scabug commented Dec 9, 2009

This code has a type error, which is correctly reported. But the compiler subesquently crashes.
https://gist.github.com/252509/293ebc9cabd39728f78cc9db5474b9f1189ca9c5

tested against 2.8.x trunk, 20091205

//Exception in thread "main" scala.tools.nsc.symtab.Types$$NoCommonType: lub/glb of //incompatible types: [X]Collection[X] and java.util.ArrayList
// at scala.tools.nsc.symtab.Types$$$$anonfun$$matchingBounds$$1.apply(Types.scala:4813)
// at scala.tools.nsc.symtab.Types$$$$anonfun$$matchingBounds$$1.apply(Types.scala:4809)
...
@scabug
Copy link
Author

scabug commented Dec 9, 2009

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

@scabug
Copy link
Author

scabug commented Dec 9, 2009

@adriaanm said:
yay, another type-showdown of higher-kinded vs raw

Martin: what should we do? silently convert the raw type to a polytype in matchingBounds? detect the anomaly earlier and give a type error instead of a crash? please advise and reassign

@scabug
Copy link
Author

scabug commented Dec 17, 2009

@odersky said:
I have no idea. I'll let you to explain the trade-offs to me when you are back in town.

@scabug
Copy link
Author

scabug commented Nov 11, 2010

rjm said:
Here's a case which involves higher-kinded types but no (explicit) raw types.

It's when the compiler tries to find a Foo for Tuple2[Int, Int] that it crashes. Put in another type at the implicitly, and it reports "could not find implicit value" as you'd expect. Actually having an implicit available doesn't make any difference; the crash still occurs.

import scala.{collection => sc}

object Test {
  trait Foo[T]

  // Haven't managed to repro without using a CanBuild or CanBuildFrom implicit parameter
  implicit def MapFoo[A, B, M[A, B] <: sc.Map[A,B]](implicit aFoo: Foo[A], bFoo: Foo[B], cb: sc.generic.CanBuild[(A, B), M[A, B]]) = new Foo[M[A,B]] {}

  // implicit object Tuple2IntIntFoo extends Foo[(Int, Int)] // no difference if this line is uncommented
  // implicit def Tuple2Foo[A, B] = new Foo[(A, B)] {}       // nor this one

  implicitly[Foo[(Int, Int)]]
}

@scabug
Copy link
Author

scabug commented Nov 12, 2010

@harrah said:
This is roughly the situation is happens for me:

scala> def x[N[X] >: M[X], M[_], G](n: N[G], m: M[G]) = null
x: [N[X] >: M[X],M[_],G](n: N[G],m: M[G])Null

scala> x(Some(3), Seq(2))
Exception in thread "main" scala.tools.nsc.symtab.Types$$NoCommonType: lub/glb of incompatible types: [X]Seq and Some

The real situation is prepending elements to a KList:
http://apocalisp.wordpress.com/2010/11/03/type-level-programming-in-scala-part-8b-klist%c2%a0basics/

@scabug
Copy link
Author

scabug commented Jan 14, 2011

@sbocq said:
Replying to [comment:7 rjm]:

Just to share a poor man's workaround. It compiles if you kind cast !CanBuild to an invariant type.

object Test {
  import scala.{collection => sc}

  trait Foo[T]

  type CB[A, B] = sc.generic.CanBuild[A, B]
  
  implicit def MapFoo[A, B, M[A, B] <: sc.Map[A,B]](implicit aFoo: Foo[A], bFoo: Foo[B], cb: CB[(A, B), M[A, B]]) = new Foo[M[A,B]] {}

  implicit object Tuple2IntIntFoo extends Foo[(Int, Int)] 

  implicitly[Foo[(Int, Int)]]
}

@scabug
Copy link
Author

scabug commented Jun 25, 2011

Commit Message Bot (anonymous) said:
(extempore in r25156) Test cases close #2782, #2171, no review.

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

No branches or pull requests

2 participants