Skip to content

Commit 899c59b

Browse files
Merge pull request #8075 from dotty-staging/fix-8042
Fix #8042: add forgotten Java constructor type params
2 parents 7bafca1 + e6f267c commit 899c59b

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ object desugar {
473473
decompose(
474474
defDef(
475475
addEvidenceParams(
476-
cpy.DefDef(ddef)(tparams = constrTparams),
476+
cpy.DefDef(ddef)(tparams = constrTparams ++ ddef.tparams),
477477
evidenceParams(constr1).map(toDefParam(_, keepAnnotations = false)))))
478478
case stat =>
479479
stat

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,18 @@ object JavaParsers {
112112
case nil => (EmptyTree, nil)
113113
}
114114
var (constr1, stats1) = pullOutFirstConstr(stats)
115-
if (constr1 == EmptyTree) constr1 = makeConstructor(List(), tparams)
116115
// A dummy first constructor is needed for Java classes so that the real constructors see the
117116
// import of the companion object. The constructor has parameter of type Unit so no Java code
118117
// can call it.
119118
// This also avoids clashes between the constructor parameter names and member names.
120119
if (needsDummyConstr) {
120+
if (constr1 == EmptyTree) constr1 = makeConstructor(List(), Nil)
121121
stats1 = constr1 :: stats1
122122
constr1 = makeConstructor(List(scalaDot(tpnme.Unit)), tparams, Flags.JavaDefined | Flags.PrivateLocal)
123123
}
124+
else if (constr1 == EmptyTree) {
125+
constr1 = makeConstructor(List(), tparams)
126+
}
124127
Template(constr1.asInstanceOf[DefDef], parents, Nil, EmptyValDef, stats1)
125128
}
126129

@@ -506,7 +509,7 @@ object JavaParsers {
506509
optThrows()
507510
List {
508511
atSpan(start) {
509-
DefDef(nme.CONSTRUCTOR, parentTParams,
512+
DefDef(nme.CONSTRUCTOR, tparams,
510513
List(vparams), TypeTree(), methodBody()).withMods(mods)
511514
}
512515
}

tests/pos/i8042/Exception.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class Exception {
2+
public <T> Exception(T actual, T matcher) { }
3+
4+
public <T> Object foo(T actual, T matcher) { return null; }
5+
6+
}

0 commit comments

Comments
 (0)