summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-09-15 22:13:15 +0000
committerPaul Phillips <paulp@improving.org>2009-09-15 22:13:15 +0000
commita5f4411f8a6dfc670efb8074e0845a1f54d65a2a (patch)
tree6c98ea04a02a13680893c6e77004afbc881474b1
parent4ccb0bf2b78919934cf67b901096331de638ee09 (diff)
downloadscala-a5f4411f8a6dfc670efb8074e0845a1f54d65a2a.tar.gz
scala-a5f4411f8a6dfc670efb8074e0845a1f54d65a2a.tar.bz2
scala-a5f4411f8a6dfc670efb8074e0845a1f54d65a2a.zip
Fix and test case for #2081.
-rwxr-xr-xsrc/compiler/scala/tools/nsc/ast/parser/Scanners.scala34
-rw-r--r--test/files/pos/bug2081.scala11
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
+}