Skip to content

Commit 794ed7d

Browse files
authored
fix(#18265): crash on extension method without type nor RHS (#18743)
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
2 parents a3d3cf8 + 07761ae commit 794ed7d

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
@@ -2651,6 +2651,8 @@ object Parsers {
26512651
parents match {
26522652
case parent :: Nil if !in.isNestedStart =>
26532653
reposition(if (parent.isType) ensureApplied(wrapNew(parent)) else parent)
2654+
case tkn if in.token == INDENT =>
2655+
New(templateBodyOpt(emptyConstructor, parents, Nil))
26542656
case _ =>
26552657
New(reposition(templateBodyOpt(emptyConstructor, parents, Nil)))
26562658
}

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
@@ -3507,7 +3507,7 @@ Occurrences:
35073507
[16:9..16:15): Object -> java/lang/Object#
35083508
[17:8..17:17): scalameta <- local4
35093509
[17:19..17:25): String -> scala/Predef.String#
3510-
[18:6..18:6): <- local6
3510+
[19:4..19:4): <- local6
35113511
[19:8..19:17): scalameta <- local5
35123512
[20:2..20:3): V -> example/StructuralTypes.V.
35133513
[20:4..20:13): scalameta -> scala/reflect/Selectable#selectDynamic().

0 commit comments

Comments
 (0)