Skip to content

Fix #8241: Allow end markers for extensions #8252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3582,17 +3582,19 @@ object Parsers {
def extensionDef(start: Offset, mods: Modifiers): ModuleDef =
in.nextToken()
val name = if isIdent && !isIdent(nme.on) then ident() else EmptyTermName
if !isIdent(nme.on) then syntaxErrorOrIncomplete("`on` expected")
if isIdent(nme.on) then in.nextToken()
val tparams = typeParamClauseOpt(ParamOwner.Def)
val extParams = paramClause(0, prefix = true)
val givenParamss = paramClauses(givenOnly = true)
possibleTemplateStart()
if !in.isNestedStart then syntaxError("Extension without extension methods")
val templ = templateBodyOpt(makeConstructor(tparams, extParams :: givenParamss), Nil, Nil)
templ.body.foreach(checkExtensionMethod(tparams, _))
val edef = ModuleDef(name, templ)
finalizeDef(edef, addFlag(mods, Given), start)
in.endMarkerScope(if name.isEmpty then nme.extension else name) {
if !isIdent(nme.on) then syntaxErrorOrIncomplete("`on` expected")
if isIdent(nme.on) then in.nextToken()
val tparams = typeParamClauseOpt(ParamOwner.Def)
val extParams = paramClause(0, prefix = true)
val givenParamss = paramClauses(givenOnly = true)
possibleTemplateStart()
if !in.isNestedStart then syntaxError("Extension without extension methods")
val templ = templateBodyOpt(makeConstructor(tparams, extParams :: givenParamss), Nil, Nil)
templ.body.foreach(checkExtensionMethod(tparams, _))
val edef = ModuleDef(name, templ)
finalizeDef(edef, addFlag(mods, Given), start)
}

/* -------- TEMPLATES ------------------------------------------- */

Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i8241.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extension NameOps on (name: String):
def isWildcard = ???
end NameOps

extension on (name: String):
def f = ???
end extension