Skip to content

Commit ba43eb1

Browse files
authored
Merge pull request #13432 from som-snytt/issue/9374
2 parents 0967522 + 0aab150 commit ba43eb1

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,7 +3649,7 @@ object Parsers {
36493649
in.observeIndented()
36503650
newLineOptWhenFollowedBy(LBRACE)
36513651
if in.isNestedStart then inDefScopeBraces(extMethods(nparams))
3652-
else { syntaxError("Extension without extension methods"); Nil }
3652+
else { syntaxErrorOrIncomplete("Extension without extension methods") ; Nil }
36533653
val result = atSpan(start)(ExtMethods(joinParams(tparams, leadParamss.toList), methods))
36543654
val comment = in.getDocComment(start)
36553655
if comment.isDefined then
@@ -3671,10 +3671,15 @@ object Parsers {
36713671
def extMethods(numLeadParams: Int): List[DefDef] = checkNoEscapingPlaceholders {
36723672
val meths = new ListBuffer[DefDef]
36733673
while
3674-
meths += extMethod(numLeadParams)
3675-
statSepOrEnd(meths, what = "extension method")
3674+
val start = in.offset
3675+
val mods = defAnnotsMods(modifierTokens)
3676+
in.token != EOF && {
3677+
accept(DEF)
3678+
meths += defDefOrDcl(start, mods, numLeadParams)
3679+
in.token != EOF && statSepOrEnd(meths, what = "extension method")
3680+
}
36763681
do ()
3677-
if meths.isEmpty then syntaxError("`def` expected")
3682+
if meths.isEmpty then syntaxErrorOrIncomplete("`def` expected")
36783683
meths.toList
36793684
}
36803685

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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\nval x: a.type = hello", storedOutput().trim)

0 commit comments

Comments
 (0)