Skip to content

Commit ed940ca

Browse files
yilinweiWojciechMazur
authored andcommitted
Fix records with type parameters (#19578).
This fixes a whole host of subtle issues. - The type parameter was not stamped correctly on the constructor causing the original error - The parsed record was not stamped with `JavaDefined`, which meant the duplicate constructors in the case of overrides were not removed. [Cherry-picked f7eb589]
1 parent 4d97216 commit ed940ca

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ object JavaParsers {
854854

855855
// generate the canonical constructor
856856
val canonicalConstructor =
857-
DefDef(nme.CONSTRUCTOR, joinParams(tparams, List(header)), TypeTree(), EmptyTree)
857+
DefDef(nme.CONSTRUCTOR, joinParams(Nil, List(header)), TypeTree(), EmptyTree)
858858
.withMods(Modifiers(Flags.JavaDefined | Flags.Synthetic, mods.privateWithin))
859859

860860
// return the trees
@@ -866,7 +866,7 @@ object JavaParsers {
866866
tparams = tparams,
867867
true
868868
)
869-
).withMods(mods)
869+
).withMods(mods.withFlags(Flags.JavaDefined | Flags.Final))
870870
}
871871
addCompanionObject(statics, recordTypeDef)
872872
end recordDecl

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ class Namer { typer: Typer =>
876876
* with a user-defined method in the same scope with a matching type.
877877
*/
878878
private def invalidateIfClashingSynthetic(denot: SymDenotation): Unit =
879+
880+
def isJavaRecord(owner: Symbol) =
881+
owner.is(JavaDefined) && owner.derivesFrom(defn.JavaRecordClass)
882+
879883
def isCaseClassOrCompanion(owner: Symbol) =
880884
owner.isClass && {
881885
if (owner.is(Module)) owner.linkedClass.is(CaseClass)
@@ -901,7 +905,7 @@ class Namer { typer: Typer =>
901905
||
902906
// remove synthetic constructor of a java Record if it clashes with a non-synthetic constructor
903907
(denot.isConstructor
904-
&& denot.owner.is(JavaDefined) && denot.owner.derivesFrom(defn.JavaRecordClass)
908+
&& isJavaRecord(denot.owner)
905909
&& denot.owner.unforcedDecls.lookupAll(denot.name).exists(c => c != denot.symbol && c.info.matches(denot.info))
906910
)
907911
)

0 commit comments

Comments
 (0)