From 2ca5d1fd29df0e70ae1ee3c389a6cd0b54cb8bef Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 11 Jun 2020 09:11:19 +0200 Subject: [PATCH 1/2] Fix #9155: Propagate @alpha on export forwarders --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 3 +++ tests/run/i9155.scala | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/run/i9155.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 8e2aaff28676..f68bceb79e24 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1129,6 +1129,9 @@ class Namer { typer: Typer => ctx.newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span) } forwarder.info = avoidPrivateLeaks(forwarder) + for annot <- sym.annotations do + if annot.tree.symbol.maybeOwner == defn.AlphaAnnot then + forwarder.addAnnotation(annot) val forwarderDef = if (forwarder.isType) tpd.TypeDef(forwarder.asType) else { diff --git a/tests/run/i9155.scala b/tests/run/i9155.scala new file mode 100644 index 000000000000..0ef470258855 --- /dev/null +++ b/tests/run/i9155.scala @@ -0,0 +1,9 @@ +object Foo: + @scala.annotation.alpha("w") def \/\/ = "W" + +object Bar: + export Foo._ + +@main def Test = + assert(Foo.getClass.getMethods.exists(_.getName == "w")) + assert(Bar.getClass.getMethods.exists(_.getName == "w")) From a7decaca72fa82dbd7d596720693ffb6735965ea Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 11 Jun 2020 10:55:11 +0200 Subject: [PATCH 2/2] Add all annotations to forwarder --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index f68bceb79e24..9d17379e66f5 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1129,9 +1129,7 @@ class Namer { typer: Typer => ctx.newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span) } forwarder.info = avoidPrivateLeaks(forwarder) - for annot <- sym.annotations do - if annot.tree.symbol.maybeOwner == defn.AlphaAnnot then - forwarder.addAnnotation(annot) + forwarder.addAnnotations(sym.annotations) val forwarderDef = if (forwarder.isType) tpd.TypeDef(forwarder.asType) else {