Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10674 from som-snytt/review/const-fold-warn
Warn more constant inexactitude
- Loading branch information
Showing
6 changed files
with
102 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
constant-warning.scala:3: warning: Evaluation of a constant expression results in an arithmetic error: / by zero | ||
constant-warning.scala:4: warning: Evaluation of a constant expression results in an arithmetic error: / by zero | ||
val fails = 1 + 2 / (3 - 2 - 1) | ||
^ | ||
constant-warning.scala:6: warning: Evaluation of a constant expression results in an arithmetic error: integer overflow, using -2147483607 | ||
val addi: Int = Int.MaxValue + 42 | ||
^ | ||
constant-warning.scala:7: warning: Evaluation of a constant expression results in an arithmetic error: integer overflow, using 2147483606 | ||
val subi: Int = Int.MinValue - 42 | ||
^ | ||
constant-warning.scala:8: warning: Evaluation of a constant expression results in an arithmetic error: integer overflow, using -2 | ||
val muli: Int = Int.MaxValue * 2 | ||
^ | ||
constant-warning.scala:9: warning: Evaluation of a constant expression results in an arithmetic error: integer overflow, using -2147483648 | ||
val divi: Int = Int.MinValue / -1 | ||
^ | ||
constant-warning.scala:10: warning: Evaluation of a constant expression results in an arithmetic error: / by zero | ||
val divz: Int = Int.MinValue / 0 | ||
^ | ||
constant-warning.scala:12: warning: Evaluation of a constant expression results in an arithmetic error: integer overflow, using 0 | ||
val long: Long = 100 * 1024 * 1024 * 1024 | ||
^ | ||
constant-warning.scala:13: warning: Evaluation of a constant expression results in an arithmetic error: long overflow, using -9223372036854775767 | ||
val addl: Long = Long.MaxValue + 42 | ||
^ | ||
constant-warning.scala:14: warning: Evaluation of a constant expression results in an arithmetic error: long overflow, using 9223372036854775766 | ||
val subl: Long = Long.MinValue - 42 | ||
^ | ||
constant-warning.scala:15: warning: Evaluation of a constant expression results in an arithmetic error: long overflow, using -2 | ||
val mull: Long = Long.MaxValue * 2 | ||
^ | ||
constant-warning.scala:16: warning: Evaluation of a constant expression results in an arithmetic error: long overflow, using -9223372036854775808 | ||
val divl: Long = Long.MinValue / -1 | ||
^ | ||
constant-warning.scala:17: warning: Evaluation of a constant expression results in an arithmetic error: / by zero | ||
val divlz: Long = Long.MinValue / 0 | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
1 warning | ||
12 warnings | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
// scalac: -Xlint:constant -Xfatal-warnings | ||
//> using options -Werror -Xlint:constant | ||
//-Vprint:cleanup (bytecode test to ensure warnable constants are folded) | ||
object Test { | ||
val fails = 1 + 2 / (3 - 2 - 1) | ||
|
||
val addi: Int = Int.MaxValue + 42 | ||
val subi: Int = Int.MinValue - 42 | ||
val muli: Int = Int.MaxValue * 2 | ||
val divi: Int = Int.MinValue / -1 | ||
val divz: Int = Int.MinValue / 0 | ||
|
||
val long: Long = 100 * 1024 * 1024 * 1024 | ||
val addl: Long = Long.MaxValue + 42 | ||
val subl: Long = Long.MinValue - 42 | ||
val mull: Long = Long.MaxValue * 2 | ||
val divl: Long = Long.MinValue / -1 | ||
val divlz: Long = Long.MinValue / 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters