Skip to content

Collective extensions is sensitive to EOF #13432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3652,7 +3652,7 @@ object Parsers {
in.observeIndented()
newLineOptWhenFollowedBy(LBRACE)
if in.isNestedStart then inDefScopeBraces(extMethods(nparams))
else { syntaxError("Extension without extension methods"); Nil }
else { syntaxErrorOrIncomplete("Extension without extension methods") ; Nil }
val result = atSpan(start)(ExtMethods(joinParams(tparams, leadParamss.toList), methods))
val comment = in.getDocComment(start)
if comment.isDefined then
Expand All @@ -3674,10 +3674,15 @@ object Parsers {
def extMethods(numLeadParams: Int): List[DefDef] = checkNoEscapingPlaceholders {
val meths = new ListBuffer[DefDef]
while
meths += extMethod(numLeadParams)
statSepOrEnd(meths, what = "extension method")
val start = in.offset
val mods = defAnnotsMods(modifierTokens)
in.token != EOF && {
accept(DEF)
meths += defDefOrDcl(start, mods, numLeadParams)
in.token != EOF && statSepOrEnd(meths, what = "extension method")
}
do ()
if meths.isEmpty then syntaxError("`def` expected")
if meths.isEmpty then syntaxErrorOrIncomplete("`def` expected")
meths.toList
}

Expand Down
6 changes: 6 additions & 0 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ class ReplCompilerTests extends ReplTest {
assertFalse(ParseResult.isIncomplete("_ + 1")) // was: assertThrows[NullPointerException]
}

@Test def `i9374 accept collective extensions`: Unit = fromInitialState { state =>
given Context = state.context
assert(ParseResult.isIncomplete("extension (x: String)"))
assert(ParseResult.isIncomplete("extension (x: String) {"))
}

@Test def testSingletonPrint = fromInitialState { implicit state =>
run("""val a = "hello"; val x: a.type = a""")
assertMultiLineEquals("val a: String = hello\nval x: a.type = hello", storedOutput().trim)
Expand Down