diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 42 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/javac/JavaScanners.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/AestheticSettings.scala | 1 | ||||
-rw-r--r-- | test/files/neg/ambiguous-float-dots.check | 13 | ||||
-rw-r--r-- | test/files/neg/ambiguous-float-dots.flags | 1 | ||||
-rw-r--r-- | test/files/neg/ambiguous-float-dots.scala | 9 | ||||
-rw-r--r-- | test/files/neg/ambiguous-float-dots2.check | 13 | ||||
-rw-r--r-- | test/files/neg/ambiguous-float-dots2.flags | 1 | ||||
-rw-r--r-- | test/files/neg/ambiguous-float-dots2.scala | 9 |
9 files changed, 85 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index ff284dd219..b0a533afc6 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -28,6 +28,7 @@ trait ScannersCommon { def warning(off: Int, msg: String): Unit def error (off: Int, msg: String): Unit def incompleteInputError(off: Int, msg: String): Unit + def deprecationWarning(off: Int, msg: String): Unit } def createKeywordArray(keywords: Seq[(Name, Int)], defaultToken: Int): (Int, Array[Int]) = { @@ -339,7 +340,18 @@ trait Scanners extends ScannersCommon { if (ch == 'x' || ch == 'X') { nextChar() base = 16 - } else { + } + else { + // !!! Let's deprecate this too, shall we? + // Can it really be worth it given the endless supply of newbies + // who have no hope whatsoever of intuiting that 012 != 12? + // Leading zero meaning octal is a relic of a darker time. + // + // Pre-fabricated future logic / warning: + // + // deprecationWarning("Treating numbers with a leading zero as octal is deprecated.") + // if (!opt.future) + // base = 8 base = 8 } getNumber() @@ -797,12 +809,28 @@ trait Scanners extends ScannersCommon { /** Convert current strVal, base to double value */ def floatVal(negated: Boolean): Double = { + val limit: Double = if (token == DOUBLELIT) Double.MaxValue else Float.MaxValue try { val value: Double = java.lang.Double.valueOf(strVal).doubleValue() + def isDeprecatedForm = { + val idx = strVal indexOf '.' + (idx == strVal.length - 1) || ( + (idx >= 0) + && (idx + 1 < strVal.length) + && (!Character.isDigit(strVal charAt (idx + 1))) + ) + } if (value > limit) syntaxError("floating point number too large") + if (isDeprecatedForm) { + if (opt.future) + syntaxError("malformed floating point number: to be part of a number, a dot must be immediately followed by a digit") + else + deprecationWarning("This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit.") + } + if (negated) -value else value } catch { case _: NumberFormatException => @@ -823,7 +851,7 @@ trait Scanners extends ScannersCommon { protected def getNumber() { def isDigit(c: Char) = java.lang.Character isDigit c val base1 = if (base < 10) 10 else base - // read 8,9's even if format is octal, produce a malformed number error afterwards. + // read 8,9's even if format is octal, produce a malformed number error afterwards. while (digit2int(ch, base1) >= 0) { putChar(ch) nextChar() @@ -915,6 +943,8 @@ trait Scanners extends ScannersCommon { */ def syntaxError(msg: String): Unit = syntaxError(offset, msg) + def deprecationWarning(msg: String): Unit = deprecationWarning(offset, msg) + /** signal an error where the input ended in the middle of a token */ def incompleteInputError(msg: String) { incompleteInputError(offset, msg) @@ -1091,7 +1121,8 @@ trait Scanners extends ScannersCommon { override val decodeUni: Boolean = !settings.nouescape.value // suppress warnings, throw exception on errors - def warning(off: Offset, msg: String): Unit = {} + def warning(off: Offset, msg: String): Unit = () + def deprecationWarning(off: Offset, msg: String): Unit = () def error (off: Offset, msg: String): Unit = throw new MalformedInput(off, msg) def incompleteInputError(off: Offset, msg: String): Unit = throw new MalformedInput(off, msg) } @@ -1101,8 +1132,9 @@ trait Scanners extends ScannersCommon { class UnitScanner(unit: CompilationUnit, patches: List[BracePatch]) extends SourceFileScanner(unit.source) { def this(unit: CompilationUnit) = this(unit, List()) - override def warning(off: Offset, msg: String) = unit.warning(unit.position(off), msg) - override def error (off: Offset, msg: String) = unit.error(unit.position(off), msg) + override def warning(off: Offset, msg: String) = unit.warning(unit.position(off), msg) + override def deprecationWarning(off: Offset, msg: String) = unit.deprecationWarning(unit.position(off), msg) + override def error (off: Offset, msg: String) = unit.error(unit.position(off), msg) override def incompleteInputError(off: Offset, msg: String) = unit.incompleteInputError(unit.position(off), msg) private var bracePatches: List[BracePatch] = patches diff --git a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala index 5422fc1c9e..45b63b0ca0 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala @@ -919,6 +919,7 @@ trait JavaScanners extends ast.parser.ScannersCommon { def warning(pos: Int, msg: String) = unit.warning(pos, msg) def error (pos: Int, msg: String) = unit. error(pos, msg) def incompleteInputError(pos: Int, msg: String) = unit.incompleteInputError(pos, msg) + def deprecationWarning(pos: Int, msg: String) = unit.deprecationWarning(pos, msg) implicit def p2g(pos: Position): Int = if (pos.isDefined) pos.point else -1 implicit def g2p(pos: Int): Position = new OffsetPosition(unit.source, pos) } diff --git a/src/compiler/scala/tools/nsc/settings/AestheticSettings.scala b/src/compiler/scala/tools/nsc/settings/AestheticSettings.scala index 7a40239057..c010c6a3ea 100644 --- a/src/compiler/scala/tools/nsc/settings/AestheticSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/AestheticSettings.scala @@ -23,6 +23,7 @@ trait AestheticSettings { def deprecation = settings.deprecation.value def experimental = settings.Xexperimental.value def fatalWarnings = settings.fatalWarnings.value + def future = settings.future.value def logClasspath = settings.Ylogcp.value def printStats = settings.Ystatistics.value def richExes = settings.YrichExes.value || sys.props.traceSourcePath.isSet diff --git a/test/files/neg/ambiguous-float-dots.check b/test/files/neg/ambiguous-float-dots.check new file mode 100644 index 0000000000..d1e71543f1 --- /dev/null +++ b/test/files/neg/ambiguous-float-dots.check @@ -0,0 +1,13 @@ +ambiguous-float-dots.scala:2: error: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit. + val x0 = 5. + ^ +ambiguous-float-dots.scala:3: error: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit. + val x1 = 5.f + ^ +ambiguous-float-dots.scala:6: error: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit. + 1.+(2) + ^ +ambiguous-float-dots.scala:7: error: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit. + 1. + 2 + ^ +four errors found diff --git a/test/files/neg/ambiguous-float-dots.flags b/test/files/neg/ambiguous-float-dots.flags new file mode 100644 index 0000000000..65faf53579 --- /dev/null +++ b/test/files/neg/ambiguous-float-dots.flags @@ -0,0 +1 @@ +-Xfatal-warnings -deprecation
\ No newline at end of file diff --git a/test/files/neg/ambiguous-float-dots.scala b/test/files/neg/ambiguous-float-dots.scala new file mode 100644 index 0000000000..58cc1b70be --- /dev/null +++ b/test/files/neg/ambiguous-float-dots.scala @@ -0,0 +1,9 @@ +class A { + val x0 = 5. + val x1 = 5.f + val y0 = 055 + + 1.+(2) + 1. + 2 + 1 + 2 +}
\ No newline at end of file diff --git a/test/files/neg/ambiguous-float-dots2.check b/test/files/neg/ambiguous-float-dots2.check new file mode 100644 index 0000000000..613601a1b2 --- /dev/null +++ b/test/files/neg/ambiguous-float-dots2.check @@ -0,0 +1,13 @@ +ambiguous-float-dots2.scala:2: error: malformed floating point number: to be part of a number, a dot must be immediately followed by a digit + val x0 = 5. + ^ +ambiguous-float-dots2.scala:6: error: malformed floating point number: to be part of a number, a dot must be immediately followed by a digit + 1.+(2) + ^ +ambiguous-float-dots2.scala:7: error: malformed floating point number: to be part of a number, a dot must be immediately followed by a digit + 1. + 2 + ^ +ambiguous-float-dots2.scala:3: error: ';' expected but 'val' found. + val x1 = 5.f + ^ +four errors found diff --git a/test/files/neg/ambiguous-float-dots2.flags b/test/files/neg/ambiguous-float-dots2.flags new file mode 100644 index 0000000000..112fc720a0 --- /dev/null +++ b/test/files/neg/ambiguous-float-dots2.flags @@ -0,0 +1 @@ +-Xfuture
\ No newline at end of file diff --git a/test/files/neg/ambiguous-float-dots2.scala b/test/files/neg/ambiguous-float-dots2.scala new file mode 100644 index 0000000000..58cc1b70be --- /dev/null +++ b/test/files/neg/ambiguous-float-dots2.scala @@ -0,0 +1,9 @@ +class A { + val x0 = 5. + val x1 = 5.f + val y0 = 055 + + 1.+(2) + 1. + 2 + 1 + 2 +}
\ No newline at end of file |