Skip to content

Commit c9dfeb2

Browse files
committed
Remove overloaded constructor for annotations
This lead to inference failures when separately compiling t1751 and t294, this did not happen under joint compilation because JavaParser does not create the overloaded constructor
1 parent 69f973a commit c9dfeb2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,6 @@ class ClassfileParser(
580580
* parameters. For Java annotations we need to fake it by making up the constructor.
581581
* Note that default getters have type Nothing. That's OK because we need
582582
* them only to signal that the corresponding parameter is optional.
583-
* If the constructor takes as last parameter an array, it can also accept
584-
* a vararg argument. We solve this by creating two constructors, one with
585-
* an array, the other with a repeated parameter.
586583
*/
587584
def addAnnotationConstructor(classInfo: Type, tparams: List[Symbol] = Nil)(implicit ctx: Context): Unit = {
588585
def addDefaultGetter(attr: Symbol, n: Int) =
@@ -618,13 +615,26 @@ class ClassfileParser(
618615
}
619616

620617
addConstr(paramTypes)
618+
619+
// The code below added an extra constructor to annotations where the
620+
// last parameter of the constructor is an Array[X] for some X, the
621+
// array was replaced by a vararg argument. Unfortunately this breaks
622+
// inference when doing:
623+
// @Annot(Array())
624+
// The constructor is overloaded so the expected type of `Array()` is
625+
// WildcardType, and the type parameter of the Array apply method gets
626+
// instantiated to `Nothing` instead of `X`.
627+
// I'm leaving this commented out in case we improve inference to make this work.
628+
// Note that if this is reenabled then JavaParser will also need to be modified
629+
// to add the extra constructor (this was not implemented before).
630+
/*
621631
if (paramTypes.nonEmpty)
622632
paramTypes.last match {
623633
case defn.ArrayOf(elemtp) =>
624634
addConstr(paramTypes.init :+ defn.RepeatedParamType.appliedTo(elemtp))
625635
case _ =>
626636
}
627-
637+
*/
628638
}
629639
}
630640

tests/pos/annot.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Test {
99

1010
@SuppressWarnings(Array("hi", "foo")) def foo2() = ??? //can be deferred as there is a non-generic method
1111

12-
@SuppressWarnings("hi") def foo3() = ??? // can be written in java and is serialized this way in bytecode. doesn't typecheck
12+
@SuppressWarnings(Array("hi")) def foo3() = ??? // can be written in java and is serialized this way in bytecode. doesn't typecheck
1313

1414
@Transient(false) def bar = ???
1515

0 commit comments

Comments
 (0)