From b006ef9ec0452a355e94b3bbe472ac8d217f1ed0 Mon Sep 17 00:00:00 2001 From: Hamza REMMAL Date: Tue, 9 Apr 2024 18:18:41 +0200 Subject: [PATCH] Add annotations in parameters for exports Co-authored-by: Jan-Pieter van den Heuvel Co-authored-by: Wessel W. Bakker --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 11 +++++++++++ tests/neg/i20127.check | 8 ++++++++ tests/neg/i20127.scala | 14 ++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/neg/i20127.check create mode 100644 tests/neg/i20127.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 15d7885776c5..4831c49f91bb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1255,6 +1255,8 @@ class Namer { typer: Typer => newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span) forwarder.info = avoidPrivateLeaks(forwarder) + + // Add annotations at the member level forwarder.addAnnotations(sym.annotations.filterConserve { annot => annot.symbol != defn.BodyAnnot && annot.symbol != defn.TailrecAnnot @@ -1290,6 +1292,15 @@ class Namer { typer: Typer => foreachDefaultGetterOf(sym.asTerm, getter => addForwarder( getter.name.asTermName, getter.asSeenFrom(path.tpe), span)) + + // adding annotations at the parameter level + // TODO: This probably needs to be filtered to avoid adding some annotation + // such as MacroAnnotations + if sym.is(Method) then + for (orig, forwarded) <- sym.paramSymss.lazyZip(forwarder.paramSymss) + (origParameter, exportedParameter) <- orig.lazyZip(forwarded) + do + exportedParameter.addAnnotations(origParameter.annotations) end addForwarder def addForwardersNamed(name: TermName, alias: TermName, span: Span): Unit = diff --git a/tests/neg/i20127.check b/tests/neg/i20127.check new file mode 100644 index 000000000000..933dd0437eb5 --- /dev/null +++ b/tests/neg/i20127.check @@ -0,0 +1,8 @@ +-- [E172] Type Error: tests/neg/i20127.scala:13:9 ---------------------------------------------------------------------- +13 | Foo.foo // error + | ^ + | foo! +-- [E172] Type Error: tests/neg/i20127.scala:14:14 --------------------------------------------------------------------- +14 | FooClone.foo // error + | ^ + | foo! diff --git a/tests/neg/i20127.scala b/tests/neg/i20127.scala new file mode 100644 index 000000000000..a21e10a13e75 --- /dev/null +++ b/tests/neg/i20127.scala @@ -0,0 +1,14 @@ +import scala.annotation.* + +trait X + +object Foo: + def foo(using @implicitNotFound("foo!") x: X) = "foo" + +object FooClone: + export Foo.foo + +object Main: + val n = 10 + Foo.foo // error + FooClone.foo // error \ No newline at end of file