Scala Programming Language
  1. Scala Programming Language
  2. SI-6667

ambiguity in first phase of implicit argument search prevents second phase unless the method call has an expected type

    Details

      Description

      class C 
      object C {
        implicit def companion = new C
      }
      
      object Test {
        implicit val inScope1, inScope2 = new C
        implicitly[C]: Unit // C.companion used.
        implicitly[C]       // ambiguity reported, rather than falling back to C.companion
      }
      

      See:

      Typers.scala
      if (original != EmptyTree && pt != WildcardType)
        typer1.silent(tpr => {
          val withImplicitArgs = tpr.applyImplicitArgs(tree)
          if (tpr.context.hasErrors) tree // silent will wrap it in SilentTypeError anyway
          else tpr.typed(withImplicitArgs, mode, pt)
        }) match {
          case SilentResultValue(result) =>
            result
          case _ =>
            debuglog("fallback on implicits: " + tree + "/" + resetAllAttrs(original))
            val tree1 = typed(resetAllAttrs(original), mode, WildcardType)
            tree1.tpe = addAnnotations(tree1, tree1.tpe)
            if (tree1.isEmpty) tree1 else adapt(tree1, mode, pt, EmptyTree)
        }
      else
        typer1.typed(typer1.applyImplicitArgs(tree), mode, pt)
      
      

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          If it's any consolation daniel, I'm even worse at this.

          Show
          Paul Phillips added a comment - If it's any consolation daniel, I'm even worse at this.
          Hide
          Jason Zaugg added a comment -

          Martin agrees that ambiguity errors in the in-scope implicit search should always prevent the implicits-of-expected-type search. I'll prepare a patch to that effect.

          Show
          Jason Zaugg added a comment - Martin agrees that ambiguity errors in the in-scope implicit search should always prevent the implicits-of-expected-type search. I'll prepare a patch to that effect.
          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/1659
          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/1675
          Hide
          Jason Zaugg added a comment -

          Demoting to a lint warning in 2.10.1, still an error in 2.11.0: https://github.com/scala/scala/pull/2063

          Show
          Jason Zaugg added a comment - Demoting to a lint warning in 2.10.1, still an error in 2.11.0: https://github.com/scala/scala/pull/2063

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Jason Zaugg
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development