Skip to content

Commit c2c937e

Browse files
committed
Make sure memoised accessors keep their meta annotation
1 parent ad520f3 commit c2c937e

File tree

7 files changed

+48
-33
lines changed

7 files changed

+48
-33
lines changed

compiler/src/dotty/tools/dotc/transform/BeanProperties.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class BeanProperties(thisPhase: DenotTransformer):
5555
a.hasOneOfMetaAnnotation(defn.BeanSetterMetaAnnot) || !a.hasOneOfMetaAnnotation(defn.BeanGetterMetaAnnot)
5656
}
5757
meth.addAnnotations(annots)
58-
DefDef(meth, (params: List[List[Tree]]) => Assign(ref(valDef.symbol), params.head.head)).withSpan(meth.span)
58+
def body(params: List[List[Tree]]): Tree = Assign(ref(valDef.symbol), params.head.head)
59+
DefDef(meth, body).withSpan(meth.span)
5960
}
6061

6162
def prefixedName(prefix: String, valName: Name) =

compiler/src/dotty/tools/dotc/transform/Memoize.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package transform
44
import core._
55
import DenotTransformers._
66
import Contexts._
7-
import Phases.phaseOf
7+
import Phases.*
88
import SymDenotations.SymDenotation
99
import Denotations._
1010
import Symbols._
@@ -130,7 +130,7 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase =>
130130
def removeUnwantedAnnotations(denot: SymDenotation, metaAnnotSym: ClassSymbol): Unit =
131131
if (sym.annotations.nonEmpty) {
132132
val cpy = sym.copySymDenotation()
133-
cpy.filterAnnotations(_.symbol.hasAnnotation(metaAnnotSym))
133+
cpy.filterAnnotations(annot => atPhase(typerPhase)(annot.hasOneOfMetaAnnotation(metaAnnotSym)))
134134
cpy.installAfter(thisPhase)
135135
}
136136

tests/run/i12492.check

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
inspecting field brandName
2-
interface MyColumnBase
3-
inspecting field companyName
4-
interface MyColumnBase
5-
inspecting method brandName
6-
inspecting method companyName
1+
inspecting field fieldName1 @MyColumnBase
2+
inspecting field fieldName2 @MyColumnBase
3+
inspecting field getterName1 @MyColumnBase
4+
inspecting field getterName2 @MyColumnBase
5+
inspecting method fieldName1
6+
inspecting method fieldName2
7+
inspecting method getterName1 @MyColumnBase
8+
inspecting method getterName2 @MyColumnBase
79
inspecting constructor MyTable
8-
inspecting param brandName
9-
inspecting param companyName
10+
inspecting param fieldName1
11+
inspecting param fieldName2
12+
inspecting param getterName1
13+
inspecting param getterName2

tests/run/i12492/MyTable.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import scala.annotation.meta.field
1+
import scala.annotation.meta.*
22

3-
type MyColumn = MyColumnBase @field
3+
type FieldColumn = MyColumnBase @field
4+
type GetterColumn = MyColumnBase @getter
45

56
class MyTable(
6-
@(MyColumnBase @field)(name="BRAND_NAME")
7-
val brandName: String,
8-
@MyColumn(name="COMPANY_NAME")
9-
val companyName: String,
7+
@(MyColumnBase @field)(name="FIELD_NAME1")
8+
val fieldName1: String,
9+
@FieldColumn(name="FIELD_NAME2")
10+
val fieldName2: String,
11+
12+
@(MyColumnBase @getter)(name="GETTER_NAME1")
13+
val getterName1: String,
14+
@GetterColumn(name="GETTER_NAME2")
15+
val getterName2: String,
1016
)

tests/run/i12492/Test.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ object Test:
55

66
for (m <- cls.getDeclaredFields.sortBy(_.getName)) {
77
m.setAccessible(true)
8-
println(s"inspecting field ${m.getName}")
8+
print(s"inspecting field ${m.getName}")
99
for a <- m.getAnnotations().sortBy(_.annotationType.toString) do
10-
println(a.annotationType)
10+
print(s" @${a.annotationType.getName}")
11+
println()
1112
}
1213

1314
for (m <- cls.getDeclaredMethods.sortBy(_.getName)) {
1415
m.setAccessible(true)
15-
println(s"inspecting method ${m.getName}")
16+
print(s"inspecting method ${m.getName}")
1617
for a <- m.getAnnotations().sortBy(_.annotationType.toString) do
17-
println(a.annotationType)
18+
print(s" @${a.annotationType.getName}")
19+
println()
1820
}
1921

2022
for c <- cls.getDeclaredConstructors.sortBy(_.getName) do
2123
c.setAccessible(true)
2224
println(s"inspecting constructor ${c.getName}")
2325
for p <- c.getParameters.sortBy(_.getName) do
24-
println(s"inspecting param ${p.getName}")
26+
print(s"inspecting param ${p.getName}")
2527
for a <- p.getAnnotations.sortBy(_.annotationType.toString) do
26-
println(a.annotationType)
28+
print(s" @${a.annotationType.getName}")
29+
println()

tests/run/i15318.check

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
inspecting field value
2-
interface JsonProperty
3-
inspecting method getValue
4-
interface JsonProperty
1+
inspecting field value @JsonProperty
2+
inspecting method getValue @JsonProperty
53
inspecting method setValue
64
inspecting method value
75
inspecting method value_$eq

tests/run/i15318/Test.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ object Test:
55

66
for (m <- cls.getDeclaredFields.sortBy(_.getName)) {
77
m.setAccessible(true)
8-
println(s"inspecting field ${m.getName}")
8+
print(s"inspecting field ${m.getName}")
99
for a <- m.getAnnotations().sortBy(_.annotationType.toString) do
10-
println(a.annotationType)
10+
print(s" @${a.annotationType.getName}")
11+
println()
1112
}
1213

1314
for (m <- cls.getDeclaredMethods.sortBy(_.getName)) {
1415
m.setAccessible(true)
15-
println(s"inspecting method ${m.getName}")
16+
print(s"inspecting method ${m.getName}")
1617
for a <- m.getAnnotations().sortBy(_.annotationType.toString) do
17-
println(a.annotationType)
18+
print(s" @${a.annotationType.getName}")
19+
println()
1820
}
1921

2022
for c <- cls.getDeclaredConstructors.sortBy(_.getName) do
2123
c.setAccessible(true)
2224
println(s"inspecting constructor ${c.getName}")
2325
for p <- c.getParameters.sortBy(_.getName) do
24-
println(s"inspecting param ${p.getName}")
26+
print(s"inspecting param ${p.getName}")
2527
for a <- p.getAnnotations.sortBy(_.annotationType.toString) do
26-
println(a.annotationType)
28+
print(s" @${a.annotationType.getName}")
29+
println()

0 commit comments

Comments
 (0)