Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implicit resolution regression, as seen in SBT. #6966

Closed
scabug opened this issue Jan 12, 2013 · 4 comments
Closed

implicit resolution regression, as seen in SBT. #6966

scabug opened this issue Jan 12, 2013 · 4 comments

Comments

@scabug
Copy link

scabug commented Jan 12, 2013

See thread:

https://groups.google.com/d/topic/simple-build-tool/-0yD3c6nJpI/discussion

@scabug
Copy link
Author

scabug commented Jan 12, 2013

Imported From: https://issues.scala-lang.org/browse/SI-6966?orig=1
Reporter: @retronym
Affected Versions: 2.11.0-M1

@scabug
Copy link
Author

scabug commented Jan 12, 2013

@retronym said:
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

@scabug
Copy link
Author

scabug commented Jan 12, 2013

@retronym said:
scala/scala#1886

@scabug
Copy link
Author

scabug commented Jan 12, 2013

@retronym said:
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants