Skip to content

Commit 358c7ea

Browse files
committed
Fix #8716 and fix #8717: Add missing extension span
1 parent 63ee630 commit 358c7ea

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3573,6 +3573,7 @@ object Parsers {
35733573
*/
35743574
def extensionDef(start: Offset, mods: Modifiers): ModuleDef =
35753575
in.nextToken()
3576+
val nameOffset = in.offset
35763577
val name = if isIdent && !isIdent(nme.on) then ident() else EmptyTermName
35773578
in.endMarkerScope(if name.isEmpty then nme.extension else name) {
35783579
val (tparams, vparamss, extensionFlag) =
@@ -3588,7 +3589,7 @@ object Parsers {
35883589
if !in.isNestedStart then syntaxError("Extension without extension methods")
35893590
val templ = templateBodyOpt(makeConstructor(tparams, vparamss), Nil, Nil)
35903591
templ.body.foreach(checkExtensionMethod(tparams, vparamss, _))
3591-
val edef = ModuleDef(name, templ)
3592+
val edef = atSpan(start, nameOffset, in.offset)(ModuleDef(name, templ))
35923593
finalizeDef(edef, addFlag(mods, Given | extensionFlag), start)
35933594
}
35943595

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
scala>extension { }
2+
1 |extension { }
3+
|^
4+
|anonymous instance must implement a type or have at least one extension method
5+
scala> extension as on
6+
1 | extension as on
7+
| ^
8+
| '(' expected, but eof found
9+
scala> extension as on (s
10+
1 | extension as on (s
11+
| ^
12+
| ':' expected, but eof found
13+
scala> extension as on (s: String) { def expand = ??? }
14+
// defined object as

0 commit comments

Comments
 (0)