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(#18265): crash on extension method without type nor RHS #18743

Conversation

i10416
Copy link
Contributor

@i10416 i10416 commented Oct 22, 2023

close #18265
This commit fixes a bug that causes Scala compiler to crash due to position error when an extension method followed by a newline has neither type annotation nor = <expr>.

This commit is based on #18445.

Co-Authored-By: @hamzaremmal

This commit fixes a bug that causes Scala compiler to crash due to position error
when an extension method followed by a newline has neither type annotation nor `= <expr>`.

This commit is based on scala#18445.

Co-Authored-By: @hamzaremmal
@@ -2577,6 +2577,8 @@ object Parsers {
parents match {
case parent :: Nil if !in.isNestedStart =>
reposition(if (parent.isType) ensureApplied(wrapNew(parent)) else parent)
case tkn if in.token == INDENT =>
Copy link
Contributor Author

@i10416 i10416 Oct 22, 2023

Choose a reason for hiding this comment

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

With brace syntax, the last token consumed by a parser is }, but with indent syntax, the last token consumed by a parser is OUTDENT, which causes mismatching spans(actual offset is n, but reposition set offset less than n). Template returned from templateBodyOpt has the exact span, so we reuse it.

Comment on lines -19 to +20
} = /*<-local6*/new:
def scalameta/*<-local5*/ = "4.0"
} = new:
/*<-local6*/def scalameta/*<-local5*/ = "4.0"
Copy link
Contributor Author

@i10416 i10416 Oct 22, 2023

Choose a reason for hiding this comment

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

I just run scala3-compiler/Test/runMain dotty.tools.dotc.semanticdb.updateExpect according to https://dotty.epfl.ch/docs/contributing/testing.html#semanticdb-tests-1. To be honest, I'm not sure what this change means.

Expect files are used as regression tests to detect changes in the compiler.
Their correctness is determined by human inspection

Which is correct, the current one or the previous one...?:thinking:

Copy link
Contributor Author

@i10416 i10416 Oct 22, 2023

Choose a reason for hiding this comment

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

If <-local6 is supposed to point to a local anonymous class, I feel the current one is correct.

@i10416 i10416 changed the title fix(#18265): crash on extension method without body fix(#18265): crash on extension method without type nor RHS Oct 22, 2023
Copy link
Contributor

@FlorianCassayre FlorianCassayre left a comment

Choose a reason for hiding this comment

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

Looks sane to me.

@hamzaremmal hamzaremmal mentioned this pull request Feb 1, 2024
@hamzaremmal hamzaremmal merged commit 794ed7d into scala:main Feb 1, 2024
18 checks passed
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur added a commit that referenced this pull request Jul 1, 2024
…" to LTS (#20876)

Backports #18743 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on new line after extension def without result type or RHS
5 participants