From a2c0519c00cc933a5477c38b20c55e4b96f773b1 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Mon, 25 Sep 2023 13:11:04 +0200 Subject: [PATCH] fix regression: inline match crash when rhs uses private inlined methods --- compiler/src/dotty/tools/dotc/ast/Trees.scala | 2 +- .../dotty/tools/dotc/CompilationTests.scala | 1 + tests/pos-special/i18589/core_0.scala | 17 +++++++++++++++++ tests/pos-special/i18589/test_1.scala | 8 ++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/pos-special/i18589/core_0.scala create mode 100644 tests/pos-special/i18589/test_1.scala diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index d3cb5865f4da..2a66eda068c9 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -455,7 +455,7 @@ object Trees { val point = span.point if name.toTermName == nme.ERROR then Span(point) - else if qualifier.span.start > span.point then // right associative + else if qualifier.span.exists && qualifier.span.start > span.point then // right associative val realName = name.stripModuleClassSuffix.lastPart Span(span.start, span.start + realName.length, point) else diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 78d7bdd3213d..e6c38c94db2e 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -38,6 +38,7 @@ class CompilationTests { compileFilesInDir("tests/pos-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking")), compileFile("tests/pos-special/utf8encoded.scala", defaultOptions.and("-encoding", "UTF8")), compileFile("tests/pos-special/utf16encoded.scala", defaultOptions.and("-encoding", "UTF16")), + compileDir("tests/pos-special/i18589", defaultOptions.and("-Ysafe-init").without("-Ycheck:all")), // Run tests for legacy lazy vals compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.posLazyValsAllowlist)), compileDir("tests/pos-special/java-param-names", defaultOptions.withJavacOnlyOptions("-parameters")), diff --git a/tests/pos-special/i18589/core_0.scala b/tests/pos-special/i18589/core_0.scala new file mode 100644 index 000000000000..d381fd0dea29 --- /dev/null +++ b/tests/pos-special/i18589/core_0.scala @@ -0,0 +1,17 @@ +import scala.deriving.Mirror + +trait NamedCodec[A, R] + +object NamedCodecPlatform { + + final class Builder[R]() { + inline def of[T](using m: Mirror.Of[T]): NamedCodec[T, R] = + inline m match { + case s: Mirror.SumOf[T] => sumInst(s) + case _: Mirror.ProductOf[T] => productInst + } + + private inline def productInst[T]: NamedCodec[T, R] = ??? + private inline def sumInst[T](m: Mirror.SumOf[T]): NamedCodec[T, R] = ??? + } +} diff --git a/tests/pos-special/i18589/test_1.scala b/tests/pos-special/i18589/test_1.scala new file mode 100644 index 000000000000..6de191970791 --- /dev/null +++ b/tests/pos-special/i18589/test_1.scala @@ -0,0 +1,8 @@ +enum Data { + case A, B, C +} + +@main def Test = { + val builder: NamedCodecPlatform.Builder[Any] = ??? + builder.of[Data] +}