@@ -3647,12 +3647,12 @@ object Parsers {
3647
3647
in.nextToken()
3648
3648
val methods =
3649
3649
if isDefIntro(modifierTokens) then
3650
- extMethod (nparams) :: Nil
3650
+ extMethodOpt (nparams).toList
3651
3651
else
3652
3652
in.observeIndented()
3653
3653
newLineOptWhenFollowedBy(LBRACE )
3654
3654
if in.isNestedStart then inDefScopeBraces(extMethods(nparams))
3655
- else { syntaxError (" Extension without extension methods" ); Nil }
3655
+ else { syntaxErrorOrIncomplete (" Extension without extension methods" ); Nil }
3656
3656
val result = atSpan(start)(ExtMethods (joinParams(tparams, leadParamss.toList), methods))
3657
3657
val comment = in.getDocComment(start)
3658
3658
if comment.isDefined then
@@ -3663,21 +3663,25 @@ object Parsers {
3663
3663
3664
3664
/** ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef
3665
3665
*/
3666
- def extMethod (numLeadParams : Int ): DefDef =
3666
+ def extMethodOpt (numLeadParams : Int ): Option [ DefDef ] =
3667
3667
val start = in.offset
3668
3668
val mods = defAnnotsMods(modifierTokens)
3669
- accept(DEF )
3670
- defDefOrDcl(start, mods, numLeadParams)
3671
-
3669
+ if in.token == DEF then
3670
+ accept(DEF )
3671
+ Some (defDefOrDcl(start, mods, numLeadParams))
3672
+ else
3673
+ None
3674
+
3672
3675
/** ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’
3673
3676
*/
3674
3677
def extMethods (numLeadParams : Int ): List [DefDef ] = checkNoEscapingPlaceholders {
3675
3678
val meths = new ListBuffer [DefDef ]
3676
3679
while
3677
- meths += extMethod(numLeadParams)
3680
+ val m = extMethodOpt(numLeadParams)
3681
+ m.foreach(meths += _)
3678
3682
statSepOrEnd(meths, what = " extension method" )
3679
3683
do ()
3680
- if meths.isEmpty then syntaxError (" `def` expected" )
3684
+ if meths.isEmpty then syntaxErrorOrIncomplete (" `def` expected" )
3681
3685
meths.toList
3682
3686
}
3683
3687
0 commit comments