From 77208c2d135b6fe658a03b3604d5ee3a1654db41 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 12 Oct 2017 19:03:55 +0200 Subject: [PATCH 1/3] Fix #3273: Extend cooking to parent types --- .../dotty/tools/dotc/core/classfile/ClassfileParser.scala | 8 +++++++- tests/pos/i3273/Bar_1.java | 8 ++++++++ tests/pos/i3273/client_2.scala | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i3273/Bar_1.java create mode 100644 tests/pos/i3273/client_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 ac4b108d3391..9a312054e4fc 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -32,6 +32,12 @@ object ClassfileParser { case tp @ AppliedType(tycon, args) => // disregard tycon itself, but map over it to visit the prefix tp.derivedAppliedType(mapOver(tycon), args.mapConserve(this)) + case tp @ TempPolyType(_, tpe) => + val tpe1 = this(tpe) + if (tpe1 eq tpe) tp else tp.copy(tpe = tpe1) + case tp @ TempClassInfoType(parents, _, _) => + val parents1 = parents.mapConserve(this) + if (parents eq parents1) tp else tp.copy(parentTypes = parents1) case _ => mapOver(tp) } @@ -154,7 +160,7 @@ class ClassfileParser( for (i <- 0 until in.nextChar) parseMember(method = false) for (i <- 0 until in.nextChar) parseMember(method = true) - classInfo = parseAttributes(classRoot.symbol, classInfo) + classInfo = cook.apply(parseAttributes(classRoot.symbol, classInfo)) if (isAnnotation) addAnnotationConstructor(classInfo) val companionClassMethod = ctx.synthesizeCompanionMethod(nme.COMPANION_CLASS_METHOD, classRoot, moduleRoot) diff --git a/tests/pos/i3273/Bar_1.java b/tests/pos/i3273/Bar_1.java new file mode 100644 index 000000000000..09c52493544b --- /dev/null +++ b/tests/pos/i3273/Bar_1.java @@ -0,0 +1,8 @@ +class Bar_1 { + static abstract class A extends B { + abstract B foo(); + } + static abstract class B { + abstract A bar(); + } +} diff --git a/tests/pos/i3273/client_2.scala b/tests/pos/i3273/client_2.scala new file mode 100644 index 000000000000..a11f17f5ed8a --- /dev/null +++ b/tests/pos/i3273/client_2.scala @@ -0,0 +1,5 @@ +class Client { + val a = (_: Bar_1.A[AnyRef]).foo() + val b = (_: Bar_1.B[AnyRef]).bar() + def test(x: Bar_1.A[AnyRef]): Bar_1.B[_] = x +} From d8ff147801a0a088b2c476918271f97e1a809586 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 13 Oct 2017 09:14:17 +0200 Subject: [PATCH 2/3] Refactor test Legacy-tests seems to always compile files together, but cooking only works for Java files read by ClassfileParser. I don't think it makes sense to change that - if we compile Java files from sources we should demand that raw types are re-written as wildcard types. So to fix this we move the offending files to pos-special and compile them only in CompilationTests. --- compiler/test/dotty/tools/dotc/CompilationTests.scala | 1 + tests/{pos => pos-special}/i3273/Bar_1.java | 0 tests/{pos => pos-special}/i3273/client_2.scala | 0 3 files changed, 1 insertion(+) rename tests/{pos => pos-special}/i3273/Bar_1.java (100%) rename tests/{pos => pos-special}/i3273/client_2.scala (100%) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 4412e8a8714b..6d2dc9ba8079 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -66,6 +66,7 @@ class CompilationTests extends ParallelTesting { ), scala2Mode ) + + compileFilesInDir("../tests/pos-special/i3273", defaultOptions) + compileFilesInDir("../tests/pos-special/spec-t5545", defaultOptions) + compileFilesInDir("../tests/pos-special/strawman-collections", defaultOptions) + compileFile("../scala2-library/src/library/scala/collection/immutable/IndexedSeq.scala", defaultOptions) + diff --git a/tests/pos/i3273/Bar_1.java b/tests/pos-special/i3273/Bar_1.java similarity index 100% rename from tests/pos/i3273/Bar_1.java rename to tests/pos-special/i3273/Bar_1.java diff --git a/tests/pos/i3273/client_2.scala b/tests/pos-special/i3273/client_2.scala similarity index 100% rename from tests/pos/i3273/client_2.scala rename to tests/pos-special/i3273/client_2.scala From 5cf516455e94fa8a35c30729650be0950ea88fff Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 13 Oct 2017 10:53:21 +0200 Subject: [PATCH 3/3] Further refactor tests To prevent failure CompilationTests we need an extra nested directory. --- tests/pos-special/i3273/{ => test}/Bar_1.java | 0 tests/pos-special/i3273/{ => test}/client_2.scala | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/pos-special/i3273/{ => test}/Bar_1.java (100%) rename tests/pos-special/i3273/{ => test}/client_2.scala (100%) diff --git a/tests/pos-special/i3273/Bar_1.java b/tests/pos-special/i3273/test/Bar_1.java similarity index 100% rename from tests/pos-special/i3273/Bar_1.java rename to tests/pos-special/i3273/test/Bar_1.java diff --git a/tests/pos-special/i3273/client_2.scala b/tests/pos-special/i3273/test/client_2.scala similarity index 100% rename from tests/pos-special/i3273/client_2.scala rename to tests/pos-special/i3273/test/client_2.scala