Skip to content

Commit 6c0cef5

Browse files
committed
Deprecate lower case long under xlint
1 parent dd1231d commit 6c0cef5

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/compiler/scala/tools/nsc/ast/parser/Scanners.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,12 +1074,15 @@ trait Scanners extends ScannersCommon {
10741074
putChar(ch)
10751075
nextChar()
10761076
}
1077+
// 1l is an acknowledged bad practice
1078+
def lintel(): Unit =
1079+
if (ch == 'l' && settings.warnLiteralSyntax) deprecationWarning(offset + cbuf.length, "Lowercase for long is ill-advised.", since="2.13.0")
10771080
// after int: 5e7f, 42L, 42.toDouble but not 42b. Repair 0d.
10781081
def restOfNumber(): Unit =
10791082
ch match {
10801083
case 'e' | 'E' | 'f' | 'F' |
10811084
'd' | 'D' => if (cbuf.isEmpty) putChar('0'); getFraction()
1082-
case 'l' | 'L' => token = LONGLIT ; setStrVal() ; nextChar()
1085+
case 'l' | 'L' => lintel() ; token = LONGLIT ; setStrVal() ; nextChar()
10831086
case _ => token = INTLIT ; setStrVal() ; checkNoLetter()
10841087
}
10851088
// consume leading digits, provisionally an Int

src/compiler/scala/tools/nsc/settings/Warnings.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ trait Warnings {
9999
val Constant = LintWarning("constant", "Evaluation of a constant arithmetic expression results in an error.")
100100
val Unused = LintWarning("unused", "Enable -Ywarn-unused:imports,privates,locals,implicits.")
101101
val NonlocalReturn = LintWarning("nonlocal-return", "A return statement used an exception for flow control.")
102+
val LiteralSyntax = LintWarning("literal-syntax", "Poor syntax choices such as `1l`.")
102103

103104
def allLintWarnings = values.toSeq.asInstanceOf[Seq[LintWarning]]
104105
}
@@ -121,6 +122,7 @@ trait Warnings {
121122
def warnConstant = lint contains Constant
122123
def lintUnused = lint contains Unused
123124
def warnNonlocalReturn = lint contains NonlocalReturn
125+
def warnLiteralSyntax = lint contains LiteralSyntax
124126

125127
// The Xlint warning group.
126128
val lint = MultiChoiceSetting(

test/files/neg/octals.check

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ octals.scala:23: warning: Octal syntax is obsolete. To avoid this warning for le
1616
octals.scala:25: warning: Octal syntax is obsolete. To avoid this warning for leading zero, use a separator char: `03_14` or `001'000`.
1717
def zeroOfNine: Int = 09 // line 28: no leading zero
1818
^
19+
octals.scala:30: warning: Lowercase for long is ill-advised.
20+
def bad = 1l
21+
^
22+
octals.scala:31: warning: Lowercase for long is ill-advised.
23+
def worse = 123l
24+
^
1925
error: No warnings can be incurred under -Xfatal-warnings.
20-
6 warnings found
26+
8 warnings found
2127
one error found

test/files/neg/octals.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// scalac: -Ywarn-octal-literal -Xfatal-warnings -deprecation
1+
// scalac: -Xlint:literal-syntax -Ywarn-octal-literal -Xfatal-warnings -deprecation
22
//
33
trait Slackenings {
44
def splitLits: Int = { 000'123 } // if they use separators, they're not migrating old code
@@ -24,3 +24,9 @@ trait Braceless {
2424

2525
def zeroOfNine: Int = 09 // line 28: no leading zero
2626
}
27+
28+
trait Lengthy {
29+
30+
def bad = 1l
31+
def worse = 123l
32+
}

0 commit comments

Comments
 (0)