@@ -21,6 +21,7 @@ import dotty.tools.dotc.core.Names.Name
2121import dotty .tools .dotc .core .NameKinds .ExpandedName
2222import dotty .tools .dotc .core .Signature
2323import dotty .tools .dotc .core .StdNames ._
24+ import dotty .tools .dotc .core .NameKinds
2425import dotty .tools .dotc .core .Symbols ._
2526import dotty .tools .dotc .core .Types
2627import dotty .tools .dotc .core .Types ._
@@ -507,7 +508,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
507508 *
508509 * must-single-thread
509510 */
510- private def addForwarder (jclass : asm.ClassVisitor , module : Symbol , m : Symbol ): Unit = {
511+ private def addForwarder (jclass : asm.ClassVisitor , module : Symbol , m : Symbol , isSynthetic : Boolean ): Unit = {
511512 val moduleName = internalName(module)
512513 val methodInfo = module.thisType.memberInfo(m)
513514 val paramJavaTypes : List [BType ] = methodInfo.firstParamTypes map toTypeKind
@@ -518,9 +519,10 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
518519 * and we don't know what classes might be subclassing the companion class. See SI-4827.
519520 */
520521 // TODO: evaluate the other flags we might be dropping on the floor here.
521- // TODO: ACC_SYNTHETIC ?
522522 val flags = GenBCodeOps .PublicStatic | (
523523 if (m.is(JavaVarargs )) asm.Opcodes .ACC_VARARGS else 0
524+ ) | (
525+ if (isSynthetic) asm.Opcodes .ACC_SYNTHETIC else 0
524526 )
525527
526528 // TODO needed? for(ann <- m.annotations) { ann.symbol.initialize }
@@ -595,7 +597,16 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
595597 report.log(s " No forwarder for non-public member $m" )
596598 else {
597599 report.log(s " Adding static forwarder for ' $m' from $jclassName to ' $moduleClass' " )
598- addForwarder(jclass, moduleClass, m)
600+ // It would be simpler to not generate forwarders for these methods,
601+ // but that wouldn't be binary-compatible with Scala 3.0.0, so instead
602+ // we generate ACC_SYNTHETIC forwarders so Java compilers ignore them.
603+ val isSynthetic =
604+ m0.name.is(NameKinds .SyntheticSetterName ) ||
605+ // Only hide bridges generated at Erasure, mixin forwarders are also
606+ // marked as bridge but shouldn't be hidden since they don't have a
607+ // non-bridge overload.
608+ m0.is(Bridge ) && m0.initial.validFor.firstPhaseId == erasurePhase.next.id
609+ addForwarder(jclass, moduleClass, m, isSynthetic)
599610 }
600611 }
601612 }
0 commit comments