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
Implicits don't abide by normal shadowing #4270
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4270?orig=1 |
@odersky said: |
@harrah said: As a simpler example: object MyImplicits {
implicit def str2int(x : String) = x.toInt
}
import MyImplicits._
object Foo {
def str2int = null
def test : Int = "5"
} This compiles, although it should not. The implicit str2int is not accessible without a prefix because the wildcard import is shadowed by the local definition. If str2int is made implicit, scalac correctly generates an error. |
@paulp said: |
@retronym said: object Test1 {
object A { implicit val x: Int = 1 }
import A.x
def x: Int = 0
implicitly[Int]
} By contrast, this does shadow: object Test2 {
object A { implicit val x: Int = 1 }
{
import A.x
def x: Int = 0
implicitly[Int]
}
} |
@retronym said: |
@retronym said: |
@OlegYch said: |
=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===
File1.scala
File2.scala
Then when running scalac File1.scala File2.scala things compile successfully.
=== What is the expected behavior? ===
From what I understand from reading the SLS, implicits are only applicable if they can be accessed on the current scope without any prefix. Shadowing should prevent them from being used in the current scope, however it appears that only implicits can shadow implicits.
When changing file2 to the following:
Now when running scalac:
=== What do you see instead? ===
Things successfully compile and they should not (according to spec).
=== Additional information ===
SLS 7.2 states:
"First, eligible are all identifiers x that can be accessed at
the point of the method call without a prefix and that denote an implicit definition
(�7.1) or an implicit parameter"
The implicit lookup rules appear to be filtering the available scope such that only implicit bindings can shadow each other.
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: