Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix regression: inline match crash when rhs uses private inlined methods #18595

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Copy link
Member

@bishabosha bishabosha Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason for these special flags? maybe a comment would help

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, basically "-Ycheck-all" option causes this test to fail. But this isn't a regression caused by #18557 it seems to had been this way before. It would be nice to fix it though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some positions in the tree are missing.

*** error while checking tests/pos-special/i18589/test_1.scala after phase inlining ***
assertion failed: position not set for NamedCodecPlatform.Builder[Any] # -1
of class dotty.tools.dotc.ast.Trees$TypeTree in tests/pos-special/i18589/test_1.scala

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Looks like it's the TypeTree in the cast in

              val Builder_this: NamedCodecPlatform.Builder[Any] =
                Builder_this.asInstanceOf[NamedCodecPlatform.Builder[Any]]

which is unpositioned. /cc @nicolasstucki

I agree you should just find a way to ignore that. I've not seen .without("-Ycheck:all") being used before, but I'm ok with it.

// 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")),
Expand Down
17 changes: 17 additions & 0 deletions tests/pos-special/i18589/core_0.scala
Original file line number Diff line number Diff line change
@@ -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] = ???
}
}
8 changes: 8 additions & 0 deletions tests/pos-special/i18589/test_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enum Data {
case A, B, C
}

@main def Test = {
val builder: NamedCodecPlatform.Builder[Any] = ???
builder.of[Data]
}