Skip to content

Don't emit mixin forwarders as final #6352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,21 @@ class BTypesFromSymbols[I <: BackendInterface](val int: I) extends BTypes {

val finalFlag = sym.getsJavaFinalFlag

// Primitives are "abstract final" to prohibit instantiation
// without having to provide any implementations, but that is an
// illegal combination of modifiers at the bytecode level so
// suppress final if abstract if present.
import asm.Opcodes._
GenBCodeOps.mkFlags(
if (privateFlag) ACC_PRIVATE else ACC_PUBLIC,
if (sym.isDeferred || sym.hasAbstractFlag) ACC_ABSTRACT else 0,
if (sym.isInterface) ACC_INTERFACE else 0,
if (finalFlag && !sym.hasAbstractFlag) ACC_FINAL else 0,

if (finalFlag &&
// Primitives are "abstract final" to prohibit instantiation
// without having to provide any implementations, but that is an
// illegal combination of modifiers at the bytecode level so
// suppress final if abstract if present.
!sym.hasAbstractFlag &&
// Mixin forwarders are bridges and can be final, but final bridges confuse some frameworks
!sym.isBridge)
ACC_FINAL else 0,
if (sym.isStaticMember) ACC_STATIC else 0,
if (sym.isBridge) ACC_BRIDGE | ACC_SYNTHETIC else 0,
if (sym.isArtifact) ACC_SYNTHETIC else 0,
Expand Down
16 changes: 16 additions & 0 deletions tests/run/t11485.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.lang.reflect.Modifier

trait HaveFinalMethod {
final def finalMethod: String = "final"
}

class Child extends HaveFinalMethod

object Test {
def main(args: Array[String]): Unit = {
val meth = classOf[Child].getMethod("finalMethod")
assert(meth.isBridge)
val mods = meth.getModifiers
assert(!Modifier.isFinal(mods))
}
}