scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Implicit infer failed for diverging in case of materialization and generic with covariance #10224

Open scabug opened 7 years ago

scabug commented 7 years ago

Simplified situation: {code:title=Test.scala|borderStyle=solid} class Gen[+A] //mark1

class Simple1 class Simple2 class Complex

object TestDMCreationContext extends App { implicit def gen[E](implicit e: E, classTag: scala.reflect.ClassTag[E]): Gen[E] = new Gen[E] //mark2 implicit def c1: Simple1 = new Simple1 implicit def c2: Simple2 = new Simple2 //mark3 implicit def c3(implicit g: Gen[Simple1]): Complex = new Complex

implicitly[Complex] } {code}

The error: Test.scala:13: error: diverging implicit expansion for type Complex starting with method c3 in object TestDMCreationContext implicitly[Complex] ^ one error found

When the code with mark1 is changed to: class Gen[A] or the code with mark2 is changed to implicit def gen[E](implicit e: E): Gen[E] = new Gen[E] or the code with mark3 is deleted, the compilation successes.

I think this is the bug about materialization

scabug commented 7 years ago

Imported From: https://issues.scala-lang.org/browse/SI-10224?orig=1 Reporter: Franklin Zhang (chigou79)