Skip to content

Commit 3ff4d90

Browse files
hamzaremmaljan-pieterwwbakker
committed
Add annotations in parameters for exports
Co-authored-by: Jan-Pieter van den Heuvel <[email protected]> Co-authored-by: Wessel W. Bakker <[email protected]>
1 parent 0bda95a commit 3ff4d90

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import config.Feature.sourceVersion
3030
import config.SourceVersion.*
3131

3232
import scala.compiletime.uninitialized
33+
import dotty.tools.dotc.util.ParsedComment.docOf
3334

3435
/** This class creates symbols from definitions and imports and gives them
3536
* lazy types.
@@ -1255,6 +1256,8 @@ class Namer { typer: Typer =>
12551256
newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span)
12561257

12571258
forwarder.info = avoidPrivateLeaks(forwarder)
1259+
1260+
// Add annotations at the member level
12581261
forwarder.addAnnotations(sym.annotations.filterConserve { annot =>
12591262
annot.symbol != defn.BodyAnnot
12601263
&& annot.symbol != defn.TailrecAnnot
@@ -1290,6 +1293,15 @@ class Namer { typer: Typer =>
12901293
foreachDefaultGetterOf(sym.asTerm,
12911294
getter => addForwarder(
12921295
getter.name.asTermName, getter.asSeenFrom(path.tpe), span))
1296+
1297+
// adding annotations at the parameter level
1298+
// TODO: This probably needs to be filtred to avoid adding some annotation
1299+
// such as MacroAnnotations
1300+
if sym.is(Method) then
1301+
for (orig, forwarded) <- sym.paramSymss.lazyZip(forwarder.paramSymss)
1302+
(origParameter, exportedParameter) <- orig.lazyZip(forwarded)
1303+
do
1304+
exportedParameter.addAnnotations(origParameter.annotations)
12931305
end addForwarder
12941306

12951307
def addForwardersNamed(name: TermName, alias: TermName, span: Span): Unit =

tests/neg/i20127.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- [E172] Type Error: tests/neg/i20127.scala:13:9 ----------------------------------------------------------------------
2+
13 | Foo.foo // error
3+
| ^
4+
| foo!
5+
-- [E172] Type Error: tests/neg/i20127.scala:14:14 ---------------------------------------------------------------------
6+
14 | FooClone.foo // error
7+
| ^
8+
| foo!

tests/neg/i20127.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.annotation.*
2+
3+
trait X
4+
5+
object Foo:
6+
def foo(using @implicitNotFound("foo!") x: X) = "foo"
7+
8+
object FooClone:
9+
export Foo.foo
10+
11+
object Main:
12+
val n = 10
13+
Foo.foo // error
14+
FooClone.foo // error

0 commit comments

Comments
 (0)