Skip to content

Commit caf30e3

Browse files
committed
fix(#18265): crash on extension method without body
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
1 parent 89a8fce commit caf30e3

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,8 @@ object Parsers {
25772577
parents match {
25782578
case parent :: Nil if !in.isNestedStart =>
25792579
reposition(if (parent.isType) ensureApplied(wrapNew(parent)) else parent)
2580+
case tkn if in.token == INDENT =>
2581+
New(templateBodyOpt(emptyConstructor, parents, Nil))
25802582
case _ =>
25812583
New(reposition(templateBodyOpt(emptyConstructor, parents, Nil)))
25822584
}

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

0 commit comments

Comments
 (0)