Skip to content

Commit 4ed478d

Browse files
committed
Fix #4430: Avoid referring to bridge methods
Scala bridge methods only come to existence during erasure, so are not visible before. But Java bridge methods come with their class files. It first I thought we should get parity, so have to ignore Java bridge methods before erasure. But that did not work, because unlike for Scala, some Java bridges are generated to allow access to inherited methods. The situation can be described using StringBuilder. It inherits a class AbstractStringBuilder which is not accessible from Scala. Here's a minimized version highlighting the problem: private class AbstractStringBuilder { def length: Int = ... def append(xs: Array[Char]): AbstractStringBuilder = ... } class StringBuilder extends AbstractStringBuilder { override def append(xs: Array[Char]): StringBuilder = ... <bridge> def length: Int = super.length <bridge> def append(xs: Array[Char]): AbstractStringBuilder = this.append(xs) } User code val sb = new StringBuilder sb.length // needs to access bridge in StringBuilder sb.append(arr) // should not access bridge in StringBuilder In the first case, `sb.length` needs to access the bridge method, as the inherited method is inaccssible. So we cannot simply hide bridge methods before erasure, as we do for Scala bridges. But in the second case, we should not access the bridge append, because it refers an inaccessible class in its result type. The fix is simple, but it took me a long time finding it: When merging denotations with the same signature (which is the case for the two appends, since results are ignored), always prefer a non-bridge over a bridge as the symbol of a JointRefDenotation.
1 parent 5a9a8c2 commit 4ed478d

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ object Config {
160160
final val showCompletions = false
161161

162162
/** If set, enables tracing */
163-
final val tracingEnabled = false
163+
final val tracingEnabled = true
164164

165165
/** Initial capacity of uniques HashMap.
166166
* Note: This MUST BE a power of two to work with util.HashSet

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ object Denotations {
488488
(!sym2.isAsConcrete(sym1) ||
489489
precedes(sym1.owner, sym2.owner) ||
490490
accessBoundary(sym2).isProperlyContainedIn(accessBoundary(sym1)) ||
491+
sym2.is(Bridge) && !sym1.is(Bridge) ||
491492
sym1.is(Method) && !sym2.is(Method)) ||
492493
sym1.info.isErroneous)
493494

0 commit comments

Comments
 (0)