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

the implicit arguments of implicit conversions do not guide type inference

    Details

      Description

      object Test {
        class Rep[T](x : T)
       
        class SomeOps[T](x : Rep[T]) { def foo = 1 }
        implicit def mkOps[X, T](x : X)(implicit conv: X => Rep[T]) : SomeOps[T] = new SomeOps(conv(x))
       
        val a: Rep[Int] = error("")
        a.foo // infers mkOps(a).foo but rejects it because the types don't work out
      // mkOps(a) will have type SomeOps[T] where T hasn't been instantiated because 
      // the implicit search for mkOps's implicit argument hasn't been performed yet
      }
      

      relevant code from Implicits.scala

          /** The type parameters to instantiate */
          val undetParams = if (isView) List() else context.outer.undetparams // TODO: why the empty list for a view? why is this a val?
      

                if (itree2.tpe.isError) SearchFailure
                else if (hasMatchingSymbol(itree1)) {
                  val tvars = undetParams map freshVar
                  println("matchesPt??: "+(undetParams, context.undetparams, context.outer.undetparams)) // note that they are different!
                  if (matchesPt(itree2.tpe /* itree2.tpe may contain typeparams from context.undetparams that will get instantiated later (during 2nd-order implicit search)*/, 
                    pt.instantiateTypeParams(undetParams, tvars), undetParams)) {
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                burmako Eugene Burmako
                Reporter:
                moors Adriaan Moors
                TracCC:
                Andreas Flierl, Daniel Sobral, Ismael Juma, Jason Zaugg, Johannes Rudolph, Mark Harrah, Seth Tisue
              • Votes:
                17 Vote for this issue
                Watchers:
                28 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: