diff options
-rwxr-xr-x | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 34 | ||||
-rw-r--r-- | test/files/pos/bug2081.scala | 11 |
2 files changed, 35 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 237394a7f1..63ec09e8cf 100755 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -711,18 +711,32 @@ trait Scanners { if (base <= 10 && ch == '.') { val lookahead = lookaheadReader lookahead.nextChar() + def restOfNumber() = { + putChar(ch) + nextChar() + getFraction() + } + lookahead.ch match { - case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | - '8' | '9' | 'd' | 'D' | 'e' | 'E' | 'f' | 'F' => - putChar(ch) - nextChar() - return getFraction() + case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => + return restOfNumber() + + /** These letters may be part of a literal, or a method invocation on an Int */ + case 'd' | 'D' | 'f' | 'F' => + lookahead.nextChar() + if (!isIdentifierPart(lookahead.ch)) + return restOfNumber() + + /** A little more special handling for e.g. 5e7 */ + case 'e' | 'E' => + lookahead.nextChar() + val ch = lookahead.ch + if (!isIdentifierPart(ch) || (ch >= '0' && ch <= '9') || ch == '+' || ch == '-') + return restOfNumber() + case _ => - if (!isIdentifierStart(lookahead.ch)) { - putChar(ch) - nextChar() - return getFraction() - } + if (!isIdentifierStart(lookahead.ch)) + return restOfNumber() } } if (base <= 10 && diff --git a/test/files/pos/bug2081.scala b/test/files/pos/bug2081.scala new file mode 100644 index 0000000000..52388464a5 --- /dev/null +++ b/test/files/pos/bug2081.scala @@ -0,0 +1,11 @@ +object ScalaForRubyists { + class RichInt(n: Int) { + def days = 1000*60*60*24*n + } + + implicit def RichInt(n: Int): RichInt = new RichInt(n) + + val x = 10.days + // a couple parser corner cases I wanted not to break + val y = 5.e0 + 5e7 +} |