Skip to content

Commit ce74bb0

Browse files
committed
[nomaster] SI-7519 Less brutal attribute resetting in adapt fallback
Prefers `resetLocalAttrs` over `resetAllAttrs`. The latter loses track of which enclosing class of the given name is referenced by a `This` node which prefixes the an applied implicit view. The code that `resetAllAttrs` originally landed in: d4c63b#L6R804 Cherry picked from 433880e Conflicts: src/compiler/scala/tools/nsc/typechecker/Typers.scala
1 parent e6a5e69 commit ce74bb0

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,9 @@ trait Typers extends Modes with Adaptations with Tags {
876876
case SilentResultValue(result) =>
877877
result
878878
case _ =>
879-
debuglog("fallback on implicits: " + tree + "/" + resetAllAttrs(original))
880-
val tree1 = typed(resetAllAttrs(original), mode, WildcardType)
879+
val resetTree = resetLocalAttrs(original)
880+
debuglog(s"fallback on implicits: ${tree}/$resetTree")
881+
val tree1 = typed(resetTree, mode, WildcardType)
881882
// Q: `typed` already calls `pluginsTyped` and `adapt`. the only difference here is that
882883
// we pass `EmptyTree` as the `original`. intended? added in 2009 (53d98e7d42) by martin.
883884
tree1.tpe = pluginsTyped(tree1.tpe, this, tree1, mode, pt)

test/files/neg/t7519.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
t7519.scala:5: error: could not find implicit value for parameter nada: Nothing
2+
locally(0 : String) // was: "value conversion is not a member of C.this.C"
3+
^
4+
t7519.scala:15: error: could not find implicit value for parameter nada: Nothing
5+
locally(0 : String) // was: "value conversion is not a member of U"
6+
^
7+
two errors found

test/files/neg/t7519.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class C {
2+
implicit def conversion(m: Int)(implicit nada: Nothing): String = ???
3+
4+
class C { // rename class to get correct error, can't find implicit: Nothing.
5+
locally(0 : String) // was: "value conversion is not a member of C.this.C"
6+
}
7+
}
8+
9+
object Test2 {
10+
trait T; trait U
11+
new T {
12+
implicit def conversion(m: Int)(implicit nada: Nothing): String = ???
13+
14+
new U { // nested anonymous classes also share a name.
15+
locally(0 : String) // was: "value conversion is not a member of U"
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)