Skip to content

Commit 47511ae

Browse files
committed
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`.
1 parent 781c25f commit 47511ae

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ object JavaParsers {
854854

855855
val accessors =
856856
(for (name, (tpt, annots)) <- fieldsByName yield
857-
DefDef(name, Nil, tpt, unimplementedExpr)
857+
DefDef(name, List(Nil), tpt, unimplementedExpr)
858858
.withMods(Modifiers(Flags.JavaDefined | Flags.Method | Flags.Synthetic))
859859
).toList
860860

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,9 +906,9 @@ class Namer { typer: Typer =>
906906
&& (definesMember || inheritsConcreteMember)
907907
)
908908
||
909-
// remove synthetic constructor of a java Record if it clashes with a non-synthetic constructor
910-
(denot.isConstructor
911-
&& isJavaRecord(denot.owner)
909+
// remove synthetic constructor or method of a java Record if it clashes with a non-synthetic constructor
910+
(isJavaRecord(denot.owner)
911+
&& (denot.isConstructor || definesMember)
912912
&& denot.owner.unforcedDecls.lookupAll(denot.name).exists(c => c != denot.symbol && c.info.matches(denot.info))
913913
)
914914
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,10 +2548,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25482548
def canBeInvalidated(sym: Symbol): Boolean =
25492549
sym.is(Synthetic)
25502550
&& (desugar.isRetractableCaseClassMethodName(sym.name) ||
2551-
(sym.isConstructor && sym.owner.derivesFrom(defn.JavaRecordClass)))
2551+
sym.owner.derivesFrom(defn.JavaRecordClass))
25522552

25532553
if !sym.info.exists then
2554-
// it's a discarded method (synthetic case class method or synthetic java record constructor), drop it
2554+
// it's a discarded method (synthetic case class method or synthetic java record constructor or overriden member), drop it
25552555
assert(canBeInvalidated(sym))
25562556
sym.owner.info.decls.openForMutations.unlink(sym)
25572557
return EmptyTree
Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public record R1(int i) {}

0 commit comments

Comments
 (0)