Skip to content

Commit d9010b9

Browse files
committed
Fix #4430: Disallow access to Java bridge methods before typer
Scala bridge methods only come to existence during erasure, so are not visible before. But Java bridge methods come with their class files. To get parity, we have to ignore them before erasure, which is done here by tweaking the `accessibleFrom` predicate. I tried to not load them in ClassfileParser in the first place, but that caused lots of errors because we do need the methods after erasure.
1 parent 5a9a8c2 commit d9010b9

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,9 @@ object Flags {
632632
/** A Java companion object */
633633
final val JavaProtected = allOf(JavaDefined, Protected)
634634

635+
/** A Java bridge method */
636+
final val JavaBridge = allOf(JavaDefined, Bridge)
637+
635638
/** A Java enum */
636639
final val JavaEnum = allOf(JavaDefined, Enum)
637640

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,13 @@ object SymDenotations {
720720
else true
721721
}
722722

723+
/** True if we refer to a Java bridge before erasure. In this case we should
724+
* pretend the bridge is not there. Scala bridge methods get created during erasure
725+
* and are therefore not visible before. But Java bridge methods are visible as
726+
* soon as the class is loaded, so we need to compensate for that difference.
727+
*/
728+
def isEarlyJavaBridgeAccess = is(JavaBridge) && !ctx.erasedTypes
729+
723730
if (pre eq NoPrefix) true
724731
else if (info eq NoType) false
725732
else {
@@ -740,7 +747,7 @@ object SymDenotations {
740747
|| ctx.phase.erasedTypes
741748
|| isProtectedAccessOK
742749
)
743-
)
750+
) && !isEarlyJavaBridgeAccess
744751
}
745752
}
746753

tests/run/i4430.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
(new java.lang.StringBuilder()).append(Array[Char](), 0, 0)
4+
}
5+
}

0 commit comments

Comments
 (0)