-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(#18265): crash on extension method without type nor RHS #18743
Conversation
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 => |
There was a problem hiding this comment.
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.
} = /*<-local6*/new: | ||
def scalameta/*<-local5*/ = "4.0" | ||
} = new: | ||
/*<-local6*/def scalameta/*<-local5*/ = "4.0" |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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