From abbdfe65d1c72c696bc35e31f38f73caef9b950b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 Apr 2021 12:33:20 +0200 Subject: [PATCH 1/4] Don't eta expand when reading Scala 2 types Eta expansion needs type parameters which can provoke a cycle. Fixes #12109. --- .../tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 2 +- tests/pos/i12109/JsonReaderDefaultValue.scala | 8 ++++++++ tests/pos/i12109/Test.scala | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i12109/JsonReaderDefaultValue.scala create mode 100644 tests/pos/i12109/Test.scala diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 018d382cdcaf..f7c8289bb637 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -792,7 +792,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas OrType(args(0), args(1), soft = false) } else if (args.nonEmpty) tycon.safeAppliedTo(EtaExpandIfHK(sym.typeParams, args.map(translateTempPoly))) - else if (sym.typeParams.nonEmpty) tycon.EtaExpand(sym.typeParams) + //else if (sym.typeParams.nonEmpty) tycon.EtaExpand(sym.typeParams) else tycon case TYPEBOUNDStpe => val lo = readTypeRef() diff --git a/tests/pos/i12109/JsonReaderDefaultValue.scala b/tests/pos/i12109/JsonReaderDefaultValue.scala new file mode 100644 index 000000000000..11348e201127 --- /dev/null +++ b/tests/pos/i12109/JsonReaderDefaultValue.scala @@ -0,0 +1,8 @@ +object JsonReaderDefaultValue extends LowPriorityDefaultValue { + class ReaderDefaultValue extends scala.annotation.StaticAnnotation +} + +trait LowPriorityDefaultValue { + @JsonReaderDefaultValue.ReaderDefaultValue + class NoDefaultValue +} diff --git a/tests/pos/i12109/Test.scala b/tests/pos/i12109/Test.scala new file mode 100644 index 000000000000..50f1aefa77e9 --- /dev/null +++ b/tests/pos/i12109/Test.scala @@ -0,0 +1,3 @@ +object Test { + JsonReaderDefaultValue +} From 59bf89fbcabcc16e68999f8bf1357588bd743e57 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 17 Apr 2021 16:17:51 +0200 Subject: [PATCH 2/4] Alternative fix: Make annotation reading lazier Fixes #12109 without causing problems elsewhere. --- .../tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index f7c8289bb637..d90e7b03e3f9 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -792,7 +792,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas OrType(args(0), args(1), soft = false) } else if (args.nonEmpty) tycon.safeAppliedTo(EtaExpandIfHK(sym.typeParams, args.map(translateTempPoly))) - //else if (sym.typeParams.nonEmpty) tycon.EtaExpand(sym.typeParams) + else if (sym.typeParams.nonEmpty) tycon.EtaExpand(sym.typeParams) else tycon case TYPEBOUNDStpe => val lo = readTypeRef() @@ -1011,9 +1011,9 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas */ protected def deferredAnnot(end: Int)(using Context): Annotation = { val start = readIndex - val atp = readTypeRef() val phase = ctx.phase - Annotation.deferred(atp.typeSymbol)( + Annotation.deferredSymAndTree( + atReadPos(start, () => atPhase(phase)(readTypeRef().typeSymbol)))( atReadPos(start, () => atPhase(phase)(readAnnotationContents(end)))) } From 0a5c927abb23e97d3ed91ff24729ca95964dd830 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 17 Apr 2021 17:14:21 +0200 Subject: [PATCH 3/4] Test with Scala 2.13 compiler --- .../sbt-test/scala2-compat/i12109/app/App.scala | 3 +++ sbt-dotty/sbt-test/scala2-compat/i12109/build.sbt | 13 +++++++++++++ .../sbt-test/scala2-compat/i12109/lib/Lib.scala | 2 ++ .../scala2-compat/i12109/project/build.properties | 1 + .../scala2-compat/i12109/project/plugins.sbt | 1 + sbt-dotty/sbt-test/scala2-compat/i12109/test | 1 + tests/pos/i12109/Test.scala | 3 --- 7 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 sbt-dotty/sbt-test/scala2-compat/i12109/app/App.scala create mode 100644 sbt-dotty/sbt-test/scala2-compat/i12109/build.sbt rename tests/pos/i12109/JsonReaderDefaultValue.scala => sbt-dotty/sbt-test/scala2-compat/i12109/lib/Lib.scala (93%) create mode 100644 sbt-dotty/sbt-test/scala2-compat/i12109/project/build.properties create mode 100644 sbt-dotty/sbt-test/scala2-compat/i12109/project/plugins.sbt create mode 100644 sbt-dotty/sbt-test/scala2-compat/i12109/test delete mode 100644 tests/pos/i12109/Test.scala diff --git a/sbt-dotty/sbt-test/scala2-compat/i12109/app/App.scala b/sbt-dotty/sbt-test/scala2-compat/i12109/app/App.scala new file mode 100644 index 000000000000..ca92cbd0db02 --- /dev/null +++ b/sbt-dotty/sbt-test/scala2-compat/i12109/app/App.scala @@ -0,0 +1,3 @@ +import i12109.* + +def test = JsonReaderDefaultValue diff --git a/sbt-dotty/sbt-test/scala2-compat/i12109/build.sbt b/sbt-dotty/sbt-test/scala2-compat/i12109/build.sbt new file mode 100644 index 000000000000..4cc8010e1d38 --- /dev/null +++ b/sbt-dotty/sbt-test/scala2-compat/i12109/build.sbt @@ -0,0 +1,13 @@ +val scala3Version = sys.props("plugin.scalaVersion") +val scala2Version = "2.13.5" + +lazy val lib = project.in(file("lib")) + .settings( + scalaVersion := scala2Version + ) + +lazy val app = project.in(file("app")) + .dependsOn(lib) + .settings( + scalaVersion := scala3Version + ) diff --git a/tests/pos/i12109/JsonReaderDefaultValue.scala b/sbt-dotty/sbt-test/scala2-compat/i12109/lib/Lib.scala similarity index 93% rename from tests/pos/i12109/JsonReaderDefaultValue.scala rename to sbt-dotty/sbt-test/scala2-compat/i12109/lib/Lib.scala index 11348e201127..db42a2d9a92a 100644 --- a/tests/pos/i12109/JsonReaderDefaultValue.scala +++ b/sbt-dotty/sbt-test/scala2-compat/i12109/lib/Lib.scala @@ -1,3 +1,5 @@ +package i12109 + object JsonReaderDefaultValue extends LowPriorityDefaultValue { class ReaderDefaultValue extends scala.annotation.StaticAnnotation } diff --git a/sbt-dotty/sbt-test/scala2-compat/i12109/project/build.properties b/sbt-dotty/sbt-test/scala2-compat/i12109/project/build.properties new file mode 100644 index 000000000000..654fe70c42c7 --- /dev/null +++ b/sbt-dotty/sbt-test/scala2-compat/i12109/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.3.12 diff --git a/sbt-dotty/sbt-test/scala2-compat/i12109/project/plugins.sbt b/sbt-dotty/sbt-test/scala2-compat/i12109/project/plugins.sbt new file mode 100644 index 000000000000..c17caab2d98c --- /dev/null +++ b/sbt-dotty/sbt-test/scala2-compat/i12109/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version")) diff --git a/sbt-dotty/sbt-test/scala2-compat/i12109/test b/sbt-dotty/sbt-test/scala2-compat/i12109/test new file mode 100644 index 000000000000..19aca297fdcf --- /dev/null +++ b/sbt-dotty/sbt-test/scala2-compat/i12109/test @@ -0,0 +1 @@ +> app/compile diff --git a/tests/pos/i12109/Test.scala b/tests/pos/i12109/Test.scala deleted file mode 100644 index 50f1aefa77e9..000000000000 --- a/tests/pos/i12109/Test.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - JsonReaderDefaultValue -} From 51f0677a4ee26ec7ed11e1979d738f56a87d5349 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 19 Apr 2021 11:02:03 +0200 Subject: [PATCH 4/4] Drop build.properties --- sbt-dotty/sbt-test/scala2-compat/i12109/project/build.properties | 1 - 1 file changed, 1 deletion(-) delete mode 100644 sbt-dotty/sbt-test/scala2-compat/i12109/project/build.properties diff --git a/sbt-dotty/sbt-test/scala2-compat/i12109/project/build.properties b/sbt-dotty/sbt-test/scala2-compat/i12109/project/build.properties deleted file mode 100644 index 654fe70c42c7..000000000000 --- a/sbt-dotty/sbt-test/scala2-compat/i12109/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.3.12