Skip to content

Commit

Permalink
fix(scala#18265): crash on extension method without body
Browse files Browse the repository at this point in the history
This commit fixes a bug that causes Scala compiler to crash due to position error
when an extension method folowed by a newline has neither type annotation nor `= <expr>`.
  • Loading branch information
i10416 committed Oct 22, 2023
1 parent 89a8fce commit f55e0cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
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 =>
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

0 comments on commit f55e0cd

Please sign in to comment.