Skip to content

Commit 5ce99ef

Browse files
yilinweiWojciechMazur
authored andcommitted
Fixes record accessors incorrect signature (#19386).
We change the proxy method to take in a single argument. This also exposed a second issue where the overriden methods were not invalidated correctly in the `Namer`. [Cherry-picked 47511ae]
1 parent 75921a5 commit 5ce99ef

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ object JavaParsers {
848848

849849
val accessors =
850850
(for (name, (tpt, annots)) <- fieldsByName yield
851-
DefDef(name, Nil, tpt, unimplementedExpr)
851+
DefDef(name, List(Nil), tpt, unimplementedExpr)
852852
.withMods(Modifiers(Flags.JavaDefined | Flags.Method | Flags.Synthetic))
853853
).toList
854854

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,9 @@ class Namer { typer: Typer =>
903903
&& (definesMember || inheritsConcreteMember)
904904
)
905905
||
906-
// remove synthetic constructor of a java Record if it clashes with a non-synthetic constructor
907-
(denot.isConstructor
908-
&& isJavaRecord(denot.owner)
906+
// remove synthetic constructor or method of a java Record if it clashes with a non-synthetic constructor
907+
(isJavaRecord(denot.owner)
908+
&& (denot.isConstructor || definesMember)
909909
&& denot.owner.unforcedDecls.lookupAll(denot.name).exists(c => c != denot.symbol && c.info.matches(denot.info))
910910
)
911911
)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2442,10 +2442,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
24422442
def canBeInvalidated(sym: Symbol): Boolean =
24432443
sym.is(Synthetic)
24442444
&& (desugar.isRetractableCaseClassMethodName(sym.name) ||
2445-
(sym.isConstructor && sym.owner.derivesFrom(defn.JavaRecordClass)))
2445+
sym.owner.derivesFrom(defn.JavaRecordClass))
24462446

24472447
if !sym.info.exists then
2448-
// it's a discarded method (synthetic case class method or synthetic java record constructor), drop it
2448+
// it's a discarded method (synthetic case class method or synthetic java record constructor or overriden member), drop it
24492449
assert(canBeInvalidated(sym))
24502450
sym.owner.info.decls.openForMutations.unlink(sym)
24512451
return EmptyTree
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test(r: R1): Unit =
2+
val i: Int = r.i()

tests/pos-java16+/i19386/R1.java

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public record R1(int i) {}

0 commit comments

Comments
 (0)