diff options
author | Paul Phillips <paulp@improving.org> | 2009-02-18 19:59:28 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-02-18 19:59:28 +0000 |
commit | 36b0e8178f74a2986bce5c9027b9a2b22a4e7527 (patch) | |
tree | 2f9722a329ecc0f8745e66407f95824de71e02d3 /src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | |
parent | 0e04072c89052a6fc296b77df64f6501c36d0c92 (diff) | |
download | scala-36b0e8178f74a2986bce5c9027b9a2b22a4e7527.tar.gz scala-36b0e8178f74a2986bce5c9027b9a2b22a4e7527.tar.bz2 scala-36b0e8178f74a2986bce5c9027b9a2b22a4e7527.zip |
Fix and test case for #1565; an anonymous funct...
Fix and test case for #1565; an anonymous function can now be used as
a statement (primarily for use in the interpreter) unless it cannot be
distinguished from a self-type declaration.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 16 |
1 files changed, 12 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 f08b08b3d7..b8b8d1bffb 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1075,9 +1075,17 @@ trait Parsers extends NewScanners with MarkupParsers { Match(stripParens(t), cases) } } - if (inToken == ARROW && location != InTemplate) { + // in order to allow anonymous functions as statements (as opposed to expressions) inside + // templates, we have to disambiguate them from self type declarations - bug #1565 + // The case still missed is unparenthesized single argument, like "x: Int => x + 1", which + // may be impossible to distinguish from a self-type and so remains an error. (See #1564) + def lhsIsTypedParamList() = t match { + case Parens(xs) if xs forall (_.isInstanceOf[Typed]) => true + case _ => false + } + if (inToken == ARROW && (location != InTemplate || lhsIsTypedParamList)) { t = atPos(inSkipToken) { - Function(convertToParams(t), if (location == Local) expr() else block()) + Function(convertToParams(t), if (location != InBlock) expr() else block()) } } stripParens(t) @@ -2501,10 +2509,10 @@ trait Parsers extends NewScanners with MarkupParsers { acceptStatSep() } else if (isExprIntro) { stats += statement(InBlock) - if (inToken != RBRACE && inToken != CASE) acceptStatSep() + if (inToken != RBRACE && inToken != CASE && inToken != EOF) acceptStatSep() } else if (isDefIntro || isLocalModifier || in.token == AT) { stats ++= localDef - if (inToken == RBRACE || inToken == CASE) { + if (inToken == RBRACE || inToken == CASE || inToken == EOF) { syntaxError("block must end in result expression, not in definition", false) stats += Literal(()).setPos(inCurrentPos) } else acceptStatSep() |