Skip to content

Commit

Permalink
Add annotations in parameters for exports (#20140)
Browse files Browse the repository at this point in the history
Closes #20127
  • Loading branch information
smarter authored Apr 9, 2024
2 parents 939f73e + b006ef9 commit 2148c8d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i20127.check
Original file line number Diff line number Diff line change
@@ -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!
14 changes: 14 additions & 0 deletions tests/neg/i20127.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2148c8d

Please sign in to comment.