Skip to content

Commit ce39ddb

Browse files
Merge pull request #8252 from dotty-staging/fix-#8241
Fix #8241: Allow end markers for extensions
2 parents 5674066 + 5168662 commit ce39ddb

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,17 +3582,19 @@ object Parsers {
35823582
def extensionDef(start: Offset, mods: Modifiers): ModuleDef =
35833583
in.nextToken()
35843584
val name = if isIdent && !isIdent(nme.on) then ident() else EmptyTermName
3585-
if !isIdent(nme.on) then syntaxErrorOrIncomplete("`on` expected")
3586-
if isIdent(nme.on) then in.nextToken()
3587-
val tparams = typeParamClauseOpt(ParamOwner.Def)
3588-
val extParams = paramClause(0, prefix = true)
3589-
val givenParamss = paramClauses(givenOnly = true)
3590-
possibleTemplateStart()
3591-
if !in.isNestedStart then syntaxError("Extension without extension methods")
3592-
val templ = templateBodyOpt(makeConstructor(tparams, extParams :: givenParamss), Nil, Nil)
3593-
templ.body.foreach(checkExtensionMethod(tparams, _))
3594-
val edef = ModuleDef(name, templ)
3595-
finalizeDef(edef, addFlag(mods, Given), start)
3585+
in.endMarkerScope(if name.isEmpty then nme.extension else name) {
3586+
if !isIdent(nme.on) then syntaxErrorOrIncomplete("`on` expected")
3587+
if isIdent(nme.on) then in.nextToken()
3588+
val tparams = typeParamClauseOpt(ParamOwner.Def)
3589+
val extParams = paramClause(0, prefix = true)
3590+
val givenParamss = paramClauses(givenOnly = true)
3591+
possibleTemplateStart()
3592+
if !in.isNestedStart then syntaxError("Extension without extension methods")
3593+
val templ = templateBodyOpt(makeConstructor(tparams, extParams :: givenParamss), Nil, Nil)
3594+
templ.body.foreach(checkExtensionMethod(tparams, _))
3595+
val edef = ModuleDef(name, templ)
3596+
finalizeDef(edef, addFlag(mods, Given), start)
3597+
}
35963598

35973599
/* -------- TEMPLATES ------------------------------------------- */
35983600

tests/pos/i8241.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extension NameOps on (name: String):
2+
def isWildcard = ???
3+
end NameOps
4+
5+
extension on (name: String):
6+
def f = ???
7+
end extension

0 commit comments

Comments
 (0)