Skip to content

Commit f7eb589

Browse files
committed
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.
1 parent 64a8865 commit f7eb589

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
@@ -860,7 +860,7 @@ object JavaParsers {
860860

861861
// generate the canonical constructor
862862
val canonicalConstructor =
863-
DefDef(nme.CONSTRUCTOR, joinParams(tparams, List(header)), TypeTree(), EmptyTree)
863+
DefDef(nme.CONSTRUCTOR, joinParams(Nil, List(header)), TypeTree(), EmptyTree)
864864
.withMods(Modifiers(Flags.JavaDefined | Flags.Synthetic, mods.privateWithin))
865865

866866
// return the trees
@@ -872,7 +872,7 @@ object JavaParsers {
872872
tparams = tparams,
873873
needsDummyConstr = true
874874
)
875-
).withMods(mods)
875+
).withMods(mods.withFlags(Flags.JavaDefined | Flags.Final))
876876
}
877877
addCompanionObject(statics, recordTypeDef)
878878
end recordDecl

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,10 @@ class Namer { typer: Typer =>
879879
* with a user-defined method in the same scope with a matching type.
880880
*/
881881
private def invalidateIfClashingSynthetic(denot: SymDenotation): Unit =
882+
883+
def isJavaRecord(owner: Symbol) =
884+
owner.is(JavaDefined) && owner.derivesFrom(defn.JavaRecordClass)
885+
882886
def isCaseClassOrCompanion(owner: Symbol) =
883887
owner.isClass && {
884888
if (owner.is(Module)) owner.linkedClass.is(CaseClass)
@@ -904,7 +908,7 @@ class Namer { typer: Typer =>
904908
||
905909
// remove synthetic constructor of a java Record if it clashes with a non-synthetic constructor
906910
(denot.isConstructor
907-
&& denot.owner.is(JavaDefined) && denot.owner.derivesFrom(defn.JavaRecordClass)
911+
&& isJavaRecord(denot.owner)
908912
&& denot.owner.unforcedDecls.lookupAll(denot.name).exists(c => c != denot.symbol && c.info.matches(denot.info))
909913
)
910914
)

0 commit comments

Comments
 (0)