File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -3652,7 +3652,7 @@ object Parsers {
36523652 in.observeIndented()
36533653 newLineOptWhenFollowedBy(LBRACE )
36543654 if in.isNestedStart then inDefScopeBraces(extMethods(nparams))
3655- else { syntaxError (" Extension without extension methods" ); Nil }
3655+ else { syntaxErrorOrIncomplete (" Extension without extension methods" ) ; Nil }
36563656 val result = atSpan(start)(ExtMethods (joinParams(tparams, leadParamss.toList), methods))
36573657 val comment = in.getDocComment(start)
36583658 if comment.isDefined then
@@ -3674,10 +3674,15 @@ object Parsers {
36743674 def extMethods (numLeadParams : Int ): List [DefDef ] = checkNoEscapingPlaceholders {
36753675 val meths = new ListBuffer [DefDef ]
36763676 while
3677- meths += extMethod(numLeadParams)
3678- statSepOrEnd(meths, what = " extension method" )
3677+ val start = in.offset
3678+ val mods = defAnnotsMods(modifierTokens)
3679+ in.token != EOF && {
3680+ accept(DEF )
3681+ meths += defDefOrDcl(start, mods, numLeadParams)
3682+ in.token != EOF && statSepOrEnd(meths, what = " extension method" )
3683+ }
36793684 do ()
3680- if meths.isEmpty then syntaxError (" `def` expected" )
3685+ if meths.isEmpty then syntaxErrorOrIncomplete (" `def` expected" )
36813686 meths.toList
36823687 }
36833688
Original file line number Diff line number Diff line change @@ -199,6 +199,12 @@ class ReplCompilerTests extends ReplTest {
199199 assertFalse(ParseResult .isIncomplete(" _ + 1" )) // was: assertThrows[NullPointerException]
200200 }
201201
202+ @ Test def `i9374 accept collective extensions` : Unit = fromInitialState { state =>
203+ given Context = state.context
204+ assert(ParseResult .isIncomplete(" extension (x: String)" ))
205+ assert(ParseResult .isIncomplete(" extension (x: String) {" ))
206+ }
207+
202208 @ Test def testSingletonPrint = fromInitialState { implicit state =>
203209 run(""" val a = "hello"; val x: a.type = a""" )
204210 assertMultiLineEquals(" val a: String = hello\n val x: a.type = hello" , storedOutput().trim)
You can’t perform that action at this time.
0 commit comments