-
Notifications
You must be signed in to change notification settings - Fork 21
type inference constraints should be carried along during search for chained implicits #2781
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2781?orig=1 |
@adriaanm said: |
@adriaanm said: class Scratch
import collection.generic.GenericCompanion
trait HasGenericCompanion[S[X] <: Traversable[X]] {
def companion: GenericCompanion[S]
}
object HasGenericCompanion {
lazy implicit val StreamHasCompanion: HasGenericCompanion[Stream] = new HasGenericCompanion[Stream] {
def companion = Stream
}
lazy implicit val ListHasCompanion: HasGenericCompanion[List] = new HasGenericCompanion[List] {
def companion = List
}
}
trait Pure[P[_]] { // TODO: can we get this to work for Pure covariant in P?
def pure[A](a: => A): P[A]
}
object Pure {
implicit def HasGenericCompanionPure[S[X] <: Traversable[X]](implicit c: HasGenericCompanion[S]) = new Pure[S] {
def pure[A](a: => A) = {
c.companion.apply(a)
}
}
}
object Test {
implicitly[HasGenericCompanion[Stream]]
val pure = Pure.HasGenericCompanionPure(implicitly[HasGenericCompanion[Stream]])
val pure2 = Pure.HasGenericCompanionPure[Stream]
// this fails with:
//$$anon.this.Pure.HasGenericCompanionPure is not a valid implicit value for this.Pure[Stream] because:
//ambiguous implicit values:
// both lazy value ListHasCompanion in object HasGenericCompanion of type => this.HasGenericCompanion[List]
// and lazy value StreamHasCompanion in object HasGenericCompanion of type => this.HasGenericCompanion[Stream]
// match expected type this.HasGenericCompanion[S]
//(fragment of Scratch.scala):43: error: could not find implicit value for parameter e: this.Pure[Stream]
implicitly[Pure[Stream]]
} |
@paulp said: |
if implicit1: X[T] requires another implicit2: Y[T], the constraints (on T) that result from the search for implicit2 should be considered in the search for implicit1.
(right now the only communication goes on through undetparams, which does not track the typevars and their constraints)
The text was updated successfully, but these errors were encountered: