diff options
-rw-r--r-- | docs/SyntaxSummary.txt | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/parsing/Parsers.scala | 3 | ||||
-rw-r--r-- | tests/pos/t4760.scala | 35 |
3 files changed, 38 insertions, 2 deletions
diff --git a/docs/SyntaxSummary.txt b/docs/SyntaxSummary.txt index 764275f92..11f23da94 100644 --- a/docs/SyntaxSummary.txt +++ b/docs/SyntaxSummary.txt @@ -129,7 +129,7 @@ grammar. | `_' ExprInParens ::= PostfixExpr `:' Type | Expr - BlockResult ::= (FunParams | [`implicit'] id `:' InfixType) => Block + BlockResult ::= (FunParams | [`implicit'] id `:' InfixType) `=>' Block | Expr1 Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] If(Parens(cond), thenp, elsep?) | `if' Expr `then' Expr [[semi] else Expr] If(cond, thenp, elsep?) diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index 71a03b9e2..d59e087cb 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1156,7 +1156,8 @@ object Parsers { */ def block(): Tree = { val stats = blockStatSeq() - if (stats.nonEmpty && !stats.last.isDef) Block(stats.init, stats.last) + def isExpr(stat: Tree) = !(stat.isDef || stat.isInstanceOf[Import]) + if (stats.nonEmpty && isExpr(stats.last)) Block(stats.init, stats.last) else Block(stats, EmptyTree) } diff --git a/tests/pos/t4760.scala b/tests/pos/t4760.scala new file mode 100644 index 000000000..039f08368 --- /dev/null +++ b/tests/pos/t4760.scala @@ -0,0 +1,35 @@ + +class Test { + // parses + def f1 = { + import scala._; + } + // b.scala:7: error: ';' expected but '}' found. + // } + // ^ + // one error found + def f2 = { + import scala._ + } + def f2b = { + import scala.collection.mutable.{ Map => MMap } + } + def f(): Unit = { + locally { + import scala.util.Properties.lineSeparator + } + } + + // parses + def f3 = { + import scala._ + 5 + } + locally { (x: Int) => + import scala.util._ + } + 1 match { + case 1 => import scala.concurrent._ + } +} + |