-
Notifications
You must be signed in to change notification settings - Fork 21
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 lookup interacts with import order #9208
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9208?orig=1 |
@retronym said: trait M
object O1 {
implicit def global: M = ???
}
object O2 {
implicit def global: M = ???
}
class Test {
def test1 = {
// the order of these imports in the same scope should not matter
import O1._
import O2.global
global
implicitly[M]
}
def test2 = {
import O2.global
import O1._
global
implicitly[M] // .. but, "error: could not find implicit value for parameter e: M"
}
} |
@retronym said: |
@Ichoran said: object P {
case class C(content: String)
object C { implicit val x = C("companion") }
// Uncomment this and u and v will resolve the same (to the companion above!)
//val x = "fish"
object O {
object First { implicit val x = C("First") }
object Second { implicit val x = C("Second") }
import First._
val u = implicitly[C]
import Second._
val v = implicitly[C]
}
val weird = (O.u,O.v)
}
P.weird |
@som-snytt said: object X { implicit def x: Int = 42 }
trait T { implicit def x: Int = 17 }
object Y extends T {
import X._
def f: Int = implicitly[Int]
} |
The Ichoran example is fixed in Scala 3, where implicits don't shadow by name. The OP no longer works because of import path checking, apparently. The retronym repro is still apropo. Relatedly, #12793 Instead of filtering while collecting implicits, it should collect all implicits offered by enclosing contexts, then filter by "accessibility" with respect to the current context. That just means lookup the identifier, which accounts for normal shadowing and access. That was suggested by a comment about |
This code compiles if the order of the imports is reversed.
Since the order of the imports correctly doesn't affect visibility or accessibility of unprefixed
global
, then it shouldn't affect the implicitness either.Reported on SO with respect to a language import, where SIP-18 was also suspected of harboring a bug.
The text was updated successfully, but these errors were encountered: