diff options
author | Paul Phillips <paulp@improving.org> | 2013-04-30 01:01:53 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-04-30 01:11:14 -0700 |
commit | d0a1f5b1c4d97f3e0368dc89691097a1b836a116 (patch) | |
tree | 6431083355f93f10f02b6e09223a896877cb1910 | |
parent | 3da1abe3a2e2752588ca8e2c7e889a321dae2037 (diff) | |
download | scala-d0a1f5b1c4d97f3e0368dc89691097a1b836a116.tar.gz scala-d0a1f5b1c4d97f3e0368dc89691097a1b836a116.tar.bz2 scala-d0a1f5b1c4d97f3e0368dc89691097a1b836a116.zip |
SI-7385 crash in erroneous code
Less crashing, more emitting errors.
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala | 9 | ||||
-rw-r--r-- | test/files/neg/t7385.check | 10 | ||||
-rw-r--r-- | test/files/neg/t7385.scala | 7 |
4 files changed, 25 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 6f79f639b9..b05902a6ef 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1332,11 +1332,10 @@ self => def parseWhile = { val start = in.offset atPos(in.skipToken()) { - val lname: Name = freshTermName(nme.WHILE_PREFIX) val cond = condExpr() newLinesOpt() val body = expr() - makeWhile(lname, cond, body) + makeWhile(start, cond, body) } } parseWhile diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index cd93221c50..b5771454f8 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -251,8 +251,13 @@ abstract class TreeBuilder { else CompoundTypeTree(Template(tps, emptyValDef, Nil)) /** Create tree representing a while loop */ - def makeWhile(lname: TermName, cond: Tree, body: Tree): Tree = { - val continu = atPos(o2p(body.pos pointOrElse wrappingPos(List(cond, body)).pos.endOrPoint)) { Apply(Ident(lname), Nil) } + def makeWhile(startPos: Int, cond: Tree, body: Tree): Tree = { + val lname = freshTermName(nme.WHILE_PREFIX) + def default = wrappingPos(List(cond, body)) match { + case p if p.isDefined => p.endOrPoint + case _ => startPos + } + val continu = atPos(o2p(body.pos pointOrElse default)) { Apply(Ident(lname), Nil) } val rhs = If(cond, Block(List(body), continu), Literal(Constant())) LabelDef(lname, Nil, rhs) } diff --git a/test/files/neg/t7385.check b/test/files/neg/t7385.check new file mode 100644 index 0000000000..70d3c3fb61 --- /dev/null +++ b/test/files/neg/t7385.check @@ -0,0 +1,10 @@ +t7385.scala:2: error: '(' expected but identifier found. + do { println("bippy") } while i<10 + ^ +t7385.scala:6: error: '(' expected but identifier found. + while i<10 { () } + ^ +t7385.scala:7: error: illegal start of simple expression +} +^ +three errors found diff --git a/test/files/neg/t7385.scala b/test/files/neg/t7385.scala new file mode 100644 index 0000000000..a7f801098b --- /dev/null +++ b/test/files/neg/t7385.scala @@ -0,0 +1,7 @@ +object Bar { + do { println("bippy") } while i<10 +} + +object Foo { + while i<10 { () } +} |