You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following, the implicit is selected despite requiring a prefix because of the local shadowing.
classAclassBtraitS {
implicitdefaToB(a: A):B=newB
}
classTextendsS {
defx:B= {
valaToB=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 prefixnewA
}
}
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.
The text was updated successfully, but these errors were encountered:
@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)
In the following, the implicit is selected despite requiring a prefix because of the local shadowing.
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 inT
or importing an implicit namedaToB
(say, from anobject P
). Puttingimplicit
in front of the localval aToB
shows the expected behavior of not selecting theS.aToB
implicit, giving a compile error.The text was updated successfully, but these errors were encountered: