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

implicit resolution regression, as seen in SBT.

    Details

      Activity

      Hide
      Jason Zaugg added a comment -

      Minimized (well, relative to where we started)

      import Ordering.{Byte, comparatorToOrdering}
      trait Format[T]
      
      object CacheIvy {
      	implicit def basicInputCache[I](implicit fmt: Format[I], eqv: Equiv[I]): InputCache[I] = null
      	implicit def arrEquiv[T](implicit t: Equiv[T]): Equiv[Array[T]] = null
      	implicit def hNilCache: InputCache[HNil] = null
      	implicit def ByteArrayFormat: Format[Array[Byte]] = null
      	type :+:[H, T <: HList] = HCons[H,T]
      	implicit def hConsCache[H, T <: HList](implicit head: InputCache[H], tail: InputCache[T]): InputCache[H :+: T] = null
      	hConsCache[Array[Byte], HNil]
      }
      
      sealed trait HList
      sealed trait HNil extends HList
      object HNil extends HNil
      final class HCons[H, T <: HList](head : H, tail : T) extends HList
      
      

      Fixed by:

      diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/comp
      index ed1e6d0..7ee6cc2 100644
      --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
      +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
      @@ -668,7 +668,7 @@ trait Implicits {
                   // duplicating the code here, but this is probably a
                   // hotspot (and you can't just call typed, need to force
                   // re-typecheck)
      -            val checked = itree2 match {
      +            .itree2 match {
                     case TypeApply(fun, args)           => typedTypeApply(itree2, EXP
                     case Apply(TypeApply(fun, args), _) => typedTypeApply(itree2, EXP
                     case t                              => t
      @@ -677,7 +677,7 @@ trait Implicits {
                   if (context.hasErrors)
                     fail("typing TypeApply reported errors for the implicit tree: " +
                   else {
      -              val result = new SearchResult(checked, subst)
      +              val result = new SearchResult(itree2, subst)
                     if (Statistics.canEnable) Statistics.incCounter(foundImplicits)
                     printInference("[success] found %s for pt %s".format(result, ptIn
                     result
      
      Show
      Jason Zaugg added a comment - Minimized (well, relative to where we started) import Ordering.{Byte, comparatorToOrdering} trait Format[T] object CacheIvy { implicit def basicInputCache[I](implicit fmt: Format[I], eqv: Equiv[I]): InputCache[I] = null implicit def arrEquiv[T](implicit t: Equiv[T]): Equiv[Array[T]] = null implicit def hNilCache: InputCache[HNil] = null implicit def ByteArrayFormat: Format[Array[Byte]] = null type :+:[H, T <: HList] = HCons[H,T] implicit def hConsCache[H, T <: HList](implicit head: InputCache[H], tail: InputCache[T]): InputCache[H :+: T] = null hConsCache[Array[Byte], HNil] } sealed trait HList sealed trait HNil extends HList object HNil extends HNil final class HCons[H, T <: HList](head : H, tail : T) extends HList Fixed by: diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/comp index ed1e6d0..7ee6cc2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -668,7 +668,7 @@ trait Implicits { // duplicating the code here, but this is probably a // hotspot (and you can't just call typed, need to force // re-typecheck) - val checked = itree2 match { + .itree2 match { case TypeApply(fun, args) => typedTypeApply(itree2, EXP case Apply(TypeApply(fun, args), _) => typedTypeApply(itree2, EXP case t => t @@ -677,7 +677,7 @@ trait Implicits { if (context.hasErrors) fail("typing TypeApply reported errors for the implicit tree: " + else { - val result = new SearchResult(checked, subst) + val result = new SearchResult(itree2, subst) if (Statistics.canEnable) Statistics.incCounter(foundImplicits) printInference("[success] found %s for pt %s".format(result, ptIn result
      Show
      Jason Zaugg added a comment - https://github.com/scala/scala/pull/1886
      Hide
      Jason Zaugg added a comment -

      The secondary problem (spurious errors in subsequent compilation unit) were due to an uncleared error buffer in the context.

      Code like:

      context.condBufferFlush(_.kind != ErrorKinds.Divergent)
      

      is surely involved.

      But I didn't find a way to trigger that problem without this bug.

      For posterity, the reproduction is:

      % git checkout v2.11.0-M1-76-ga2a37ed
      % cat test/files/pos/t6966.scala
      import Ordering.{Byte, comparatorToOrdering}
      trait Format[T]
      trait InputCache[T]
      object CacheIvy {
      	implicit def basicInputCache[I](implicit fmt: Format[I], eqv: Equiv[I]): InputCache[I] = null
      	implicit def arrEquiv[T](implicit t: Equiv[T]): Equiv[Array[T]] = null
      	implicit def hNilCache: InputCache[HNil] = null
      	implicit def ByteArrayFormat: Format[Array[Byte]] = null
      	type :+:[H, T <: HList] = HCons[H,T]
      	implicit def hConsCache[H, T <: HList](implicit head: InputCache[H], tail: InputCache[T]): InputCache[H :+: T] = null
      	hConsCache[Array[Byte], HNil]
      }
      
      sealed trait HList
      sealed trait HNil extends HList
      object HNil extends HNil
      final class HCons[H, T <: HList](head : H, tail : T) extends HList
      
      % ~/code/scala cat test/files/pos/t6966b.scala
      object X  {
      	val (xs, _) = List((1, 2)).unzip
      	xs: List[Int]
      }
      
      % squalac test/files/pos/t6966.scala test/files/pos/t6966b.scala 
      test/files/pos/t6966.scala:11: error: diverging implicit expansion for type Equiv[Array[Byte]]
      starting with method comparatorToOrdering in trait LowPriorityOrderingImplicits
      	hConsCache[Array[Byte], HNil]
                        ^
      test/files/pos/t6966b.scala:3: error: type mismatch;
       found   : Any
       required: List[Int]
      	xs: List[Int]
              ^
      test/files/pos/t6966b.scala:3: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
      	xs: List[Int]
                ^
      one warning found
      two errors found
      
      Show
      Jason Zaugg added a comment - The secondary problem (spurious errors in subsequent compilation unit) were due to an uncleared error buffer in the context. Code like: context.condBufferFlush(_.kind != ErrorKinds.Divergent) is surely involved. But I didn't find a way to trigger that problem without this bug. For posterity, the reproduction is: % git checkout v2.11.0-M1-76-ga2a37ed % cat test/files/pos/t6966.scala import Ordering.{Byte, comparatorToOrdering} trait Format[T] trait InputCache[T] object CacheIvy { implicit def basicInputCache[I](implicit fmt: Format[I], eqv: Equiv[I]): InputCache[I] = null implicit def arrEquiv[T](implicit t: Equiv[T]): Equiv[Array[T]] = null implicit def hNilCache: InputCache[HNil] = null implicit def ByteArrayFormat: Format[Array[Byte]] = null type :+:[H, T <: HList] = HCons[H,T] implicit def hConsCache[H, T <: HList](implicit head: InputCache[H], tail: InputCache[T]): InputCache[H :+: T] = null hConsCache[Array[Byte], HNil] } sealed trait HList sealed trait HNil extends HList object HNil extends HNil final class HCons[H, T <: HList](head : H, tail : T) extends HList % ~/code/scala cat test/files/pos/t6966b.scala object X { val (xs, _) = List((1, 2)).unzip xs: List[Int] } % squalac test/files/pos/t6966.scala test/files/pos/t6966b.scala test/files/pos/t6966.scala:11: error: diverging implicit expansion for type Equiv[Array[Byte]] starting with method comparatorToOrdering in trait LowPriorityOrderingImplicits hConsCache[Array[Byte], HNil] ^ test/files/pos/t6966b.scala:3: error: type mismatch; found : Any required: List[Int] xs: List[Int] ^ test/files/pos/t6966b.scala:3: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses xs: List[Int] ^ one warning found two errors found

        People

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

          Dates

          • Created:
            Updated:
            Resolved:

            Development