Deprecated ambiguous dot syntaxes.
1.+(2) - what is it? Is it 3 or 3.0? Come scala 2.11 you won't have to not know (or even not know there's something you don't know.) 1.+(2) will then be safely considered equivalent to 1 + 2, because any dot not followed by a digit is not part of a number. Primarily, that's these forms: 3.f 3.d 3. If you prefer an error to a warning, use -Xfuture. Let's deprecate 012 == 10 too! (See comment.) References SI-5089, no review. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25985 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
fcf009beb2
commit
26c0e05a6a
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -0,0 +1 @@
|
|||
-Xfatal-warnings -deprecation
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
class A {
|
||||
val x0 = 5.
|
||||
val x1 = 5.f
|
||||
val y0 = 055
|
||||
|
||||
1.+(2)
|
||||
1. + 2
|
||||
1 + 2
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1 @@
|
|||
-Xfuture
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
class A {
|
||||
val x0 = 5.
|
||||
val x1 = 5.f
|
||||
val y0 = 055
|
||||
|
||||
1.+(2)
|
||||
1. + 2
|
||||
1 + 2
|
||||
}
|
||||
Loading…
Reference in New Issue