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 ignores non-implicit shadowing #3453

Closed
scabug opened this issue May 19, 2010 · 2 comments
Closed

Implicit resolution ignores non-implicit shadowing #3453

scabug opened this issue May 19, 2010 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented May 19, 2010

In the following, the implicit is selected despite requiring a prefix because of the local shadowing.

class A
class B

trait S {
    implicit def aToB(a: A): B = new B
}

class T extends S {
    def x: B = {
        val aToB = 3
        // doesn't compile, because aToB method requires 'T.this.' prefix
        //aToB(new A)
        
        // compiles, using T.this.aToB,
        //   despite it not being accessible without a prefix
        new A
    }
}

As I understand it, Section 7.2 of the spec says that the first part of implicit resolution finds implicits accessible without a prefix. Ch. 2 says that a local identifier shadows an inherited identifier because it has the same precedence but is in an inner scope, which is why aToB(new A) doesn't compile. Therefore, S.aToB should not be considered for implicit resolution.

The same behavior occurs when defining aToB directly in T or importing an implicit named aToB (say, from an object P). Putting implicit in front of the local val aToB shows the expected behavior of not selecting the S.aToB implicit, giving a compile error.

@scabug
Copy link
Author

scabug commented May 19, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3453?orig=1
Reporter: @harrah

@scabug
Copy link
Author

scabug commented May 26, 2010

@adriaanm said:
(In r22046) also consider non-implicit locals when checking shadowing of implicits: closes #3453

nonImplicitSynonymInScope implements the predicate that is used in tryImplicit's checks for shadowing of locally defined implicits
benchmarking shows the predicate does not significantly affect quick.comp+quick.lib (goes from 11min to 11min2s on my machine -- no optimisations)

review by odersky

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

No branches or pull requests

2 participants