Skip to content

Commit

Permalink
Merge pull request #13432 from som-snytt/issue/9374
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 14, 2021
2 parents 0967522 + 0aab150 commit ba43eb1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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 @@ -3649,7 +3649,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 @@ -3671,10 +3671,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

0 comments on commit ba43eb1

Please sign in to comment.