Skip to content

Commit 0aab150

Browse files
dos65som-snytt
authored andcommitted
Collective extensions is sensitive to EOF
This allows REPL to input extensions.
1 parent 8bb0ca7 commit 0aab150

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
@@ -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

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)