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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2782?orig=1 |
@adriaanm said: 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 |
@odersky said: |
rjm said: It's when the compiler tries to find a 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)]]
} |
@harrah said: 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: |
@sbocq said: 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)]]
} |
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
The text was updated successfully, but these errors were encountered: