@@ -1929,7 +1929,10 @@ object Parsers {
19291929 commaSeparated(importExpr) match {
19301930 case t :: rest =>
19311931 // The first import should start at the position of the keyword.
1932- t.withPos(t.pos.withStart(offset)) :: rest
1932+ val firstPos =
1933+ if (t.pos.exists) t.pos.withStart(offset)
1934+ else Position (offset, in.lastOffset)
1935+ t.withPos(firstPos) :: rest
19331936 case nil => nil
19341937 }
19351938 }
@@ -2422,22 +2425,35 @@ object Parsers {
24222425 (self, if (stats.isEmpty) List (EmptyTree ) else stats.toList)
24232426 }
24242427
2425- /** RefineStatSeq ::= RefineStat {semi RefineStat}
2426- * RefineStat ::= Dcl
2427- * |
2428- * (in reality we admit Defs and filter them out afterwards)
2428+ /** RefineStatSeq ::= RefineStat {semi RefineStat}
2429+ * RefineStat ::= ‘val’ VarDcl
2430+ * | ‘def’ DefDcl
2431+ * | ‘type’ {nl} TypeDcl
2432+ * (in reality we admit Defs and vars and filter them out afterwards in `checkLegal`)
24292433 */
24302434 def refineStatSeq (): List [Tree ] = {
24312435 val stats = new ListBuffer [Tree ]
2436+ def checkLegal (tree : Tree ): List [Tree ] = {
2437+ val isLegal = tree match {
2438+ case tree : ValDef => tree.rhs.isEmpty && ! tree.mods.flags.is(Mutable )
2439+ case tree : DefDef => tree.rhs.isEmpty
2440+ case tree : TypeDef => true
2441+ case _ => false
2442+ }
2443+ if (isLegal) tree :: Nil
2444+ else {
2445+ syntaxError(" illegal refinement" , tree.pos)
2446+ Nil
2447+ }
2448+ }
24322449 while (! isStatSeqEnd) {
2433- if (isDclIntro) {
2434- stats += defOrDcl(in.offset, Modifiers ())
2435- } else if (! isStatSep) {
2450+ if (isDclIntro)
2451+ stats ++= checkLegal( defOrDcl(in.offset, Modifiers () ))
2452+ else if (! isStatSep)
24362453 syntaxErrorOrIncomplete(
24372454 " illegal start of declaration" +
24382455 (if (inFunReturnType) " (possible cause: missing `=' in front of current method body)"
24392456 else " " ))
2440- }
24412457 acceptStatSepUnlessAtEnd()
24422458 }
24432459 stats.toList
0 commit comments