@@ -225,7 +225,6 @@ object Parsers {
225225 || defIntroTokens.contains(in.token)
226226 || allowedMods.contains(in.token)
227227 || in.isSoftModifierInModifierPosition && ! excludedSoftModifiers.contains(in.name)
228- || isIdent(nme.extension) && followingIsOldExtension()
229228
230229 def isStatSep : Boolean = in.isNewLine || in.token == SEMI
231230
@@ -919,23 +918,10 @@ object Parsers {
919918 skipParams()
920919 lookahead.isIdent(nme.as)
921920
922- def followingIsNewExtension () =
921+ def followingIsExtension () =
923922 val next = in.lookahead.token
924923 next == LBRACKET || next == LPAREN
925924
926- def followingIsOldExtension () =
927- val lookahead = in.LookaheadScanner ()
928- lookahead.nextToken()
929- if lookahead.isIdent && ! lookahead.isIdent(nme.on) then
930- lookahead.nextToken()
931- if lookahead.isNewLine then
932- lookahead.nextToken()
933- lookahead.isIdent(nme.on)
934- || lookahead.token == LBRACE
935- || lookahead.token == COLON
936-
937- def followingIsExtension () = followingIsOldExtension() || followingIsNewExtension()
938-
939925/* --------- OPERAND/OPERATOR STACK --------------------------------------- */
940926
941927 var opStack : List [OpInfo ] = Nil
@@ -1311,7 +1297,7 @@ object Parsers {
13111297 case stat : MemberDef if ! stat.name.isEmpty =>
13121298 if stat.name == nme.CONSTRUCTOR then in.token == THIS
13131299 else in.isIdent && in.name == stat.name.toTermName
1314- case ModuleDef (_, Template (_, Nil , _, _)) | ExtMethods (_, _, _) =>
1300+ case ExtMethods (_, _, _) =>
13151301 in.token == IDENTIFIER && in.name == nme.extension
13161302 case PackageDef (pid : RefTree , _) =>
13171303 in.isIdent && in.name == pid.name
@@ -3305,7 +3291,7 @@ object Parsers {
33053291 def extParamss () =
33063292 try paramClause(0 , prefix = true ) :: Nil
33073293 finally
3308- mods1 = addFlag(mods, Extension )
3294+ mods1 = addFlag(mods, ExtensionMethod )
33093295 if in.token == DOT then in.nextToken()
33103296 else
33113297 isInfix = true
@@ -3319,14 +3305,14 @@ object Parsers {
33193305 (Nil , Nil )
33203306 val ident = termIdent()
33213307 var name = ident.name.asTermName
3322- if mods1.is(Extension ) then name = name.toExtensionName
3308+ if mods1.is(ExtensionMethod ) then name = name.toExtensionName
33233309 if isInfix && ! name.isOperatorName then
33243310 val infixAnnot = Apply (wrapNew(scalaAnnotationDot(tpnme.infix)), Nil )
33253311 .withSpan(Span (start, start))
33263312 mods1 = mods1.withAddedAnnotation(infixAnnot)
33273313 val tparams =
33283314 if in.token == LBRACKET then
3329- if mods1.is(Extension ) then syntaxError(" no type parameters allowed here" )
3315+ if mods1.is(ExtensionMethod ) then syntaxError(" no type parameters allowed here" )
33303316 typeParamClause(ParamOwner .Def )
33313317 else leadingTparams
33323318 val vparamss = paramClauses() match
@@ -3465,11 +3451,8 @@ object Parsers {
34653451 case GIVEN =>
34663452 givenDef(start, mods, atSpan(in.skipToken()) { Mod .Given () })
34673453 case _ =>
3468- if isIdent(nme.extension) && followingIsOldExtension() then
3469- extensionDef(start, mods)
3470- else
3471- syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition ())
3472- EmptyTree
3454+ syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition ())
3455+ EmptyTree
34733456 }
34743457
34753458 /** ClassDef ::= id ClassConstr TemplateOpt
@@ -3563,9 +3546,9 @@ object Parsers {
35633546 def checkExtensionMethod (tparams : List [Tree ],
35643547 vparamss : List [List [Tree ]], stat : Tree ): Unit = stat match {
35653548 case stat : DefDef =>
3566- if stat.mods.is(Extension ) && vparamss.nonEmpty then
3549+ if stat.mods.is(ExtensionMethod ) && vparamss.nonEmpty then
35673550 syntaxError(i " no extension method allowed here since leading parameter was already given " , stat.span)
3568- else if ! stat.mods.is(Extension ) && vparamss.isEmpty then
3551+ else if ! stat.mods.is(ExtensionMethod ) && vparamss.isEmpty then
35693552 syntaxError(i " an extension method is required here " , stat.span)
35703553 else if tparams.nonEmpty && stat.tparams.nonEmpty then
35713554 syntaxError(i " extension method cannot have type parameters since some were already given previously " ,
@@ -3614,28 +3597,6 @@ object Parsers {
36143597 finalizeDef(gdef, mods1, start)
36153598 }
36163599
3617- /** ExtensionDef ::= [id] [‘on’ ExtParamClause {UsingParamClause}] TemplateBody
3618- */
3619- def extensionDef (start : Offset , mods : Modifiers ): ModuleDef =
3620- in.nextToken()
3621- val nameOffset = in.offset
3622- val name = if isIdent && ! isIdent(nme.on) then ident() else EmptyTermName
3623- val (tparams, vparamss, extensionFlag) =
3624- if isIdent(nme.on) then
3625- in.nextToken()
3626- val tparams = typeParamClauseOpt(ParamOwner .Def )
3627- val extParams = paramClause(0 , prefix = true )
3628- val givenParamss = paramClauses(givenOnly = true )
3629- (tparams, extParams :: givenParamss, Extension )
3630- else
3631- (Nil , Nil , EmptyFlags )
3632- possibleTemplateStart()
3633- if ! in.isNestedStart then syntaxError(" Extension without extension methods" )
3634- val templ = templateBodyOpt(makeConstructor(tparams, vparamss), Nil , Nil )
3635- templ.body.foreach(checkExtensionMethod(tparams, vparamss, _))
3636- val edef = atSpan(start, nameOffset, in.offset)(ModuleDef (name, templ))
3637- finalizeDef(edef, addFlag(mods, Given | extensionFlag), start)
3638-
36393600 /** Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’
36403601 * {UsingParamClause} ExtMethods
36413602 */
@@ -3816,7 +3777,7 @@ object Parsers {
38163777 stats ++= importClause(IMPORT , mkImport(outermost))
38173778 else if (in.token == EXPORT )
38183779 stats ++= importClause(EXPORT , Export .apply)
3819- else if isIdent(nme.extension) && followingIsNewExtension () then
3780+ else if isIdent(nme.extension) && followingIsExtension () then
38203781 stats += extension()
38213782 else if isDefIntro(modifierTokens)
38223783 stats +++= defOrDcl(in.offset, defAnnotsMods(modifierTokens))
@@ -3870,7 +3831,7 @@ object Parsers {
38703831 stats ++= importClause(IMPORT , mkImport())
38713832 else if (in.token == EXPORT )
38723833 stats ++= importClause(EXPORT , Export .apply)
3873- else if isIdent(nme.extension) && followingIsNewExtension () then
3834+ else if isIdent(nme.extension) && followingIsExtension () then
38743835 stats += extension()
38753836 else if (isDefIntro(modifierTokensOrCase))
38763837 stats +++= defOrDcl(in.offset, defAnnotsMods(modifierTokens))
@@ -3952,7 +3913,7 @@ object Parsers {
39523913 stats += expr(Location .InBlock )
39533914 else if in.token == IMPLICIT && ! in.inModifierPosition() then
39543915 stats += closure(in.offset, Location .InBlock , modifiers(BitSet (IMPLICIT )))
3955- else if isIdent(nme.extension) && followingIsNewExtension () then
3916+ else if isIdent(nme.extension) && followingIsExtension () then
39563917 stats += extension()
39573918 else if isDefIntro(localModifierTokens, excludedSoftModifiers = Set (nme.`opaque`)) then
39583919 stats +++= localDef(in.offset)
0 commit comments