From 00b0a9c1c38e75809562728e87a6884a3061d673 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 7 Nov 2020 22:33:05 +0100 Subject: [PATCH 1/2] sig2typeBounds: avoid unnecessary work When skiptvs we don't need to construct a type at all, we're just skipping over part of the byte stream. --- .../dotc/core/classfile/ClassfileParser.scala | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 10c8a9051199..8bac1b68cac1 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -461,11 +461,17 @@ class ClassfileParser( val ts = new ListBuffer[Type] while (sig(index) == ':') { index += 1 - if (sig(index) != ':') // guard against empty class bound - ts += sig2type(tparams, skiptvs) + if (sig(index) != ':') { // guard against empty class bound + val tp = sig2type(tparams, skiptvs) + if (!skiptvs) + ts += tp + } + } + if (!skiptvs) { + val bound = if ts.isEmpty then defn.AnyType else ts.reduceLeft(AndType.apply) + TypeBounds.upper(bound) } - val bound = if ts.isEmpty then defn.AnyType else ts.reduceLeft(AndType.apply) - TypeBounds.upper(bound) + else NoType } var tparams = classTParams From 7675ad29d6a825a45fe2adff3b1f5858b6f04d1f Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 7 Nov 2020 20:48:37 +0100 Subject: [PATCH 2/2] Handle raw types in bounds of Java class type params Fixes #10225. --- .../src/dotty/tools/dotc/core/classfile/ClassfileParser.scala | 2 +- tests/pos-java-interop-separate/i10225/A_1.java | 1 + tests/pos-java-interop-separate/i10225/B_1.java | 3 +++ tests/pos-java-interop-separate/i10225/Test_2.scala | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/pos-java-interop-separate/i10225/A_1.java create mode 100644 tests/pos-java-interop-separate/i10225/B_1.java create mode 100644 tests/pos-java-interop-separate/i10225/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 8bac1b68cac1..870ef6c8bf8d 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -464,7 +464,7 @@ class ClassfileParser( if (sig(index) != ':') { // guard against empty class bound val tp = sig2type(tparams, skiptvs) if (!skiptvs) - ts += tp + ts += cook(tp) } } if (!skiptvs) { diff --git a/tests/pos-java-interop-separate/i10225/A_1.java b/tests/pos-java-interop-separate/i10225/A_1.java new file mode 100644 index 000000000000..2be9eb8680eb --- /dev/null +++ b/tests/pos-java-interop-separate/i10225/A_1.java @@ -0,0 +1 @@ +class A_1 {} diff --git a/tests/pos-java-interop-separate/i10225/B_1.java b/tests/pos-java-interop-separate/i10225/B_1.java new file mode 100644 index 000000000000..e3b96c798d15 --- /dev/null +++ b/tests/pos-java-interop-separate/i10225/B_1.java @@ -0,0 +1,3 @@ +class B_1 { + public B_1(S s) { } +} diff --git a/tests/pos-java-interop-separate/i10225/Test_2.scala b/tests/pos-java-interop-separate/i10225/Test_2.scala new file mode 100644 index 000000000000..959bc72add3b --- /dev/null +++ b/tests/pos-java-interop-separate/i10225/Test_2.scala @@ -0,0 +1,4 @@ +object Test { + val a = new A_1[String] + val b = new B_1(a) +}