Skip to content

Commit

Permalink
Fix mapping of annotations containing defs
Browse files Browse the repository at this point in the history
  • Loading branch information
mbovel committed Mar 15, 2024
1 parent 3d5cf9c commit e51b8f1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object Annotations {
if tm.isRange(x) then x
else
val tp1 = tm(tree.tpe)
foldOver(if tp1 frozen_=:= tree.tpe then x else tp1, tree)
foldOver(if tp1 eq tree.tpe then x else tp1, tree)
val diff = findDiff(NoType, args)
if tm.isRange(diff) then EmptyAnnotation
else if diff.exists then derivedAnnotation(tm.mapOver(tree))
Expand Down
33 changes: 33 additions & 0 deletions tests/printing/dependent-annot-19846.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[[syntax trees at end of typer]] // tests/printing/dependent-annot-19846.scala
package <empty> {
class lambdaAnnot(g: () => Int) extends scala.annotation.Annotation(),
annotation.StaticAnnotation {
private[this] val g: () => Int
}
final lazy module val Test: Test = new Test()
final module class Test() extends Object() { this: Test.type =>
val y: Int = ???
val z:
Int @lambdaAnnot(
{
def $anonfun(): Int = Test.y
closure($anonfun)
}
)
= f(Test.y)
}
final lazy module val dependent-annot-19846$package:
dependent-annot-19846$package = new dependent-annot-19846$package()
final module class dependent-annot-19846$package() extends Object() {
this: dependent-annot-19846$package.type =>
def f(x: Int):
Int @lambdaAnnot(
{
def $anonfun(): Int = x
closure($anonfun)
}
)
= x
}
}

5 changes: 5 additions & 0 deletions tests/printing/dependent-annot-19846.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class lambdaAnnot(g: () => Int) extends annotation.StaticAnnotation
def f(x: Int): Int @lambdaAnnot(() => x) = x
object Test:
val y: Int = ???
val z /*: Int @lambdaAnnot(() => y) */ = f(y)

0 comments on commit e51b8f1

Please sign in to comment.