Skip to content

Commit dd88b71

Browse files
hamzaremmaljan-pieterwwbakker
committed
Add annotations in parameters for exports
Co-authored-by: Jan-Pieter van den Heuvel <jan-pieter@piozum.com> Co-authored-by: Wessel W. Bakker <wwbakker@gmail.com>
1 parent 0bda95a commit dd88b71

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,8 @@ class Namer { typer: Typer =>
12551255
newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span)
12561256

12571257
forwarder.info = avoidPrivateLeaks(forwarder)
1258+
1259+
// Add annotations at the member level
12581260
forwarder.addAnnotations(sym.annotations.filterConserve { annot =>
12591261
annot.symbol != defn.BodyAnnot
12601262
&& annot.symbol != defn.TailrecAnnot
@@ -1290,6 +1292,15 @@ class Namer { typer: Typer =>
12901292
foreachDefaultGetterOf(sym.asTerm,
12911293
getter => addForwarder(
12921294
getter.name.asTermName, getter.asSeenFrom(path.tpe), span))
1295+
1296+
// adding annotations at the parameter level
1297+
// TODO: This probably needs to be filtred to avoid adding some annotation
1298+
// such as MacroAnnotations
1299+
if sym.is(Method) then
1300+
for (orig, forwarded) <- sym.paramSymss.lazyZip(forwarder.paramSymss)
1301+
(origParameter, exportedParameter) <- orig.lazyZip(forwarded)
1302+
do
1303+
exportedParameter.addAnnotations(origParameter.annotations)
12931304
end addForwarder
12941305

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

tests/neg/i20127.check

+8
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

+14
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)