Skip to content

Commit c4b5824

Browse files
Backport "fix(#18265): crash on extension method without type nor RHS" to LTS (#20876)
Backports #18743 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 5647505 + 45faafb commit c4b5824

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+2
Original file line numberDiff line numberDiff line change
@@ -2607,6 +2607,8 @@ object Parsers {
26072607
parents match {
26082608
case parent :: Nil if !in.isNestedStart =>
26092609
reposition(if (parent.isType) ensureApplied(wrapNew(parent)) else parent)
2610+
case tkn if in.token == INDENT =>
2611+
New(templateBodyOpt(emptyConstructor, parents, Nil))
26102612
case _ =>
26112613
New(reposition(templateBodyOpt(emptyConstructor, parents, Nil)))
26122614
}

tests/neg/i18265.check

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- [E019] Syntax Error: tests/neg/i18265.scala:5:13 --------------------------------------------------------------------
2+
5 | def twice // error
3+
| ^
4+
| Missing return type
5+
|
6+
| longer explanation available when compiling with `-explain`

tests/neg/i18265.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait Foo
2+
3+
val foo = new Foo:
4+
extension (s: String)
5+
def twice // error

tests/semanticdb/expect/StructuralTypes.expect.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object StructuralTypes/*<-example::StructuralTypes.*/:
1616

1717
val V/*<-example::StructuralTypes.V.*/: Object/*->java::lang::Object#*/ {
1818
def scalameta/*<-local4*/: String/*->scala::Predef.String#*/
19-
} = /*<-local6*/new:
20-
def scalameta/*<-local5*/ = "4.0"
19+
} = new:
20+
/*<-local6*/def scalameta/*<-local5*/ = "4.0"
2121
V/*->example::StructuralTypes.V.*/.scalameta/*->scala::reflect::Selectable#selectDynamic().*/
2222
end StructuralTypes/*->example::StructuralTypes.*/

tests/semanticdb/metac.expect

+1-1
Original file line numberDiff line numberDiff line change
@@ -3472,7 +3472,7 @@ Occurrences:
34723472
[16:9..16:15): Object -> java/lang/Object#
34733473
[17:8..17:17): scalameta <- local4
34743474
[17:19..17:25): String -> scala/Predef.String#
3475-
[18:6..18:6): <- local6
3475+
[19:4..19:4): <- local6
34763476
[19:8..19:17): scalameta <- local5
34773477
[20:2..20:3): V -> example/StructuralTypes.V.
34783478
[20:4..20:13): scalameta -> scala/reflect/Selectable#selectDynamic().

0 commit comments

Comments
 (0)