Skip to content

Commit 6de3755

Browse files
i10416WojciechMazur
authored andcommitted
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 [Cherry-picked caf30e3]
1 parent 4ddb9d5 commit 6de3755

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
@@ -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

0 commit comments

Comments
 (0)