Skip to content

Commit

Permalink
Emit all bridge methods non-final
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Mar 17, 2022
1 parent 003dc97 commit 3d069a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/transform/Erasure.scala
Expand Up @@ -565,7 +565,7 @@ abstract class Erasure extends InfoTransform
if (!bridgeNeeded)
return

var newFlags = (member.flags | BRIDGE | ARTIFACT) & ~(ACCESSOR | DEFERRED | LAZY)
var newFlags = (member.flags | BRIDGE | ARTIFACT) & ~(ACCESSOR | DEFERRED | LAZY | FINAL)
// If `member` is a ModuleSymbol, the bridge should not also be a ModuleSymbol. Otherwise we
// end up with two module symbols with the same name in the same scope, which is surprising
// when implementing later phases.
Expand Down
27 changes: 27 additions & 0 deletions test/files/run/t12532.scala
@@ -0,0 +1,27 @@
class Sync

class Async extends Sync { def x = 1 }

trait Base {
def foo: Sync
}

trait BaseSync extends Base {
override def foo: Sync
}

trait BaseAsync extends Base {
override def foo: Async
}

abstract class ImplAsync extends BaseAsync {
final override def foo: Async = new Async
}

final class StrangeClass extends ImplAsync with BaseSync

object Test {
def main(args: Array[String]): Unit = {
assert((new StrangeClass).foo.x == 1)
}
}
4 changes: 2 additions & 2 deletions test/files/run/t6028.check
Expand Up @@ -33,7 +33,7 @@ package <empty> {
<specialized> def apply$mcI$sp(): Int = $anonfun$foo$1.this.$outer.classParam.+($anonfun$foo$1.this.$outer.field()).+($anonfun$foo$1.this.methodParam$1).+($anonfun$foo$1.this.methodLocal$1);
<synthetic> <paramaccessor> <artifact> private[this] val $outer: T = _;
<synthetic> <stable> <artifact> def $outer(): T = $anonfun$foo$1.this.$outer;
final <bridge> <artifact> def apply(): Object = scala.Int.box($anonfun$foo$1.this.apply());
<bridge> <artifact> def apply(): Object = scala.Int.box($anonfun$foo$1.this.apply());
<synthetic> <paramaccessor> private[this] val methodParam$1: Int = _;
<synthetic> <paramaccessor> private[this] val methodLocal$1: Int = _
};
Expand Down Expand Up @@ -73,7 +73,7 @@ package <empty> {
} finally ();
<synthetic> <paramaccessor> <artifact> private[this] val $outer: T = _;
<synthetic> <stable> <artifact> def $outer(): T = $anonfun$tryy$1.this.$outer;
final <bridge> <artifact> def apply(): Object = {
<bridge> <artifact> def apply(): Object = {
$anonfun$tryy$1.this.apply();
scala.runtime.BoxedUnit.UNIT
};
Expand Down

0 comments on commit 3d069a2

Please sign in to comment.