-
Notifications
You must be signed in to change notification settings - Fork 21
Implicit lookup failure in return type aliases #5070
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-5070?orig=1 |
@paulp said: |
@retronym said (edited on May 20, 2012 7:16:05 PM UTC): object ImplicitVsTypeAlias {
trait For {
val map = 0
}
type _For = For
class M {
type __For = For
// 1.
implicit def toFor: __For = ???
// 2.
// implicit def toFor: _For = ???
// 3.
// implicit def toFor: For = ???
}
def use1(m1: M) {
import m1.toFor
// Fails with 1, works with 2 and 3
implicitly[{def map: Int}]
// works with 1, 2 and 3.
implicitly[For]
}
val m2: M = ???
def use2 {
import m2.toFor
// works with 1, 2 and 3.
implicitly[{def map: Int}]
// works with 1, 2 and 3.
implicitly[For]
}
}
|
@retronym said (edited on May 20, 2012 8:41:41 PM UTC): => m1.__For to: "=> ?#__For" It only affects the This mapped type no longer conforms to the expected type, How can we be more discriminating here? We only want to find types that are dependent on a method parameter in the method that provides the candiate implicit. ... Oh, just found this: // more precise conceptually, but causes cyclic errors: (paramss exists (_ contains sym))
override def isImmediatelyDependent = (sym ne NoSymbol) && (sym.owner.isMethod && sym.isValueParameter)
|
@adriaanm said: |
@adriaanm said: |
@retronym said (edited on Feb 21, 2015 3:41:57 AM UTC): trait Web {
type LocalName
}
trait Companion1[A]
trait WebDSL[W <: Web] {
trait LocalNameCompanion extends Companion1[W#LocalName] {
type A = String
}
implicit val LocalName: LocalNameCompanion
}
object Test {
def t[W <: Web](implicit webDSL: WebDSL[W]): Unit = {
import webDSL._
implicitly[LocalNameCompanion] // succeeds
implicitly[Companion1[W#LocalName]] // fails
}
}
As reported https://groups.google.com/forum/#!topic/scala-user/Wvh8q85gFAs |
@odersky said: |
@retronym said (edited on Feb 21, 2015 12:09:02 PM UTC): trait A {
type T
}
object O {
implicit def b(implicit x: A): x.T = error("")
}
class Test {
import O._
implicit val a: A = new A {}
implicitly[a.T] // works in scalac, not in dotty
implicitly[a.T](b(a)) // works
}
With regards to the bugs above, my hunch is that scalac could be fixed by using a |
@retronym said: This seems more promising: https://github.com/retronym/scala/compare/ticket/5070?expand=1 I think we can do better than: // more precise conceptually, but causes cyclic errors: (paramss exists (_ contains sym))
override def isImmediatelyDependent = (sym ne NoSymbol) && (sym.owner.isMethod && sym.isValueParameter) .. from within implicit search, as we know the the current implicit method in question, and need only check that the type is not dependent on one of its parameters. |
I stumbled upon a similar issue when working with Slick. Here's a minimal reproduction without dependencies: import scala.language.implicitConversions
class JdbcProfile {
type Aliased = String
implicit val qToHasResult: Int => Aliased = ???
}
class Example1(profile: JdbcProfile) {
import profile.qToHasResult
//compiles
println(5.length)
}
object Example2 {
def make(profile: JdbcProfile): Unit = {
import profile.qToHasResult
//doesn't compile
println(5.length)
}
} |
The original bug report compiles in Scala 3, but @kubukoz's doesn't. Jakub, if you're convinced that should compile, I'd suggest opening a ticket over at https://github.com/lampepfl/dotty/issues . |
For some reason, implicit lookup fails when type-alias is used in return types:
The text was updated successfully, but these errors were encountered: