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

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: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.

New(templateBodyOpt(emptyConstructor, parents, Nil))
case _ =>
New(reposition(templateBodyOpt(emptyConstructor, parents, Nil)))
}
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i18265.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- [E019] Syntax Error: tests/neg/i18265.scala:5:13 --------------------------------------------------------------------
5 | def twice // error
| ^
| Missing return type
|
| longer explanation available when compiling with `-explain`
5 changes: 5 additions & 0 deletions tests/neg/i18265.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait Foo

val foo = new Foo:
extension (s: String)
def twice // error
4 changes: 2 additions & 2 deletions tests/semanticdb/expect/StructuralTypes.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object StructuralTypes/*<-example::StructuralTypes.*/:

val V/*<-example::StructuralTypes.V.*/: Object/*->java::lang::Object#*/ {
def scalameta/*<-local4*/: String/*->scala::Predef.String#*/
} = /*<-local6*/new:
def scalameta/*<-local5*/ = "4.0"
} = new:
/*<-local6*/def scalameta/*<-local5*/ = "4.0"
Comment on lines -19 to +20
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.

V/*->example::StructuralTypes.V.*/.scalameta/*->scala::reflect::Selectable#selectDynamic().*/
end StructuralTypes/*->example::StructuralTypes.*/
2 changes: 1 addition & 1 deletion tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -3472,7 +3472,7 @@ Occurrences:
[16:9..16:15): Object -> java/lang/Object#
[17:8..17:17): scalameta <- local4
[17:19..17:25): String -> scala/Predef.String#
[18:6..18:6): <- local6
[19:4..19:4): <- local6
[19:8..19:17): scalameta <- local5
[20:2..20:3): V -> example/StructuralTypes.V.
[20:4..20:13): scalameta -> scala/reflect/Selectable#selectDynamic().
Expand Down
Loading