Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-10224

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

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Type Checker
    • Labels:
      None
    • Environment:

      scala 2.12.1
      jdk 1.8.x

      Description

      Simplified situation:

      Test.scala

      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]
      }
      

      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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              chigou79 Franklin Zhang
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: