Skip to content

Commit e3c822c

Browse files
committed
Prompt the user to give the L suffix on numbers
Fixes #4878
1 parent 1f6b4d3 commit e3c822c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

java/src/processing/mode/java/Compiler.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public void close() { }
166166
exception = new SketchException(errorMessage);
167167
}
168168

169+
String[] parts = null;
170+
169171
if (errorMessage.startsWith("The import ") &&
170172
errorMessage.endsWith("cannot be resolved")) {
171173
// The import poo cannot be resolved
@@ -253,9 +255,18 @@ public void close() { }
253255
// "Duplicate nested type xxx"
254256
// "Duplicate local variable xxx"
255257

258+
} else if (null != (parts = PApplet.match(errorMessage,
259+
"literal (\\S*) of type (\\S*) is out of range"))) {
260+
if ("int".equals(parts[2])) {
261+
exception.setMessage("The type int can't handle numbers that big. Try "
262+
+ parts[1] + "L to upgrade to long.");
263+
} else {
264+
// I'd like to give an essay on BigInteger and BigDecimal, but
265+
// this margin is too narrow to contain it.
266+
exception.setMessage("Even the type " + parts[2] + " can't handle "
267+
+ parts[1] + ". Research big numbers in Java.");
268+
}
256269
} else {
257-
String[] parts = null;
258-
259270
// The method xxx(String) is undefined for the type Temporary_XXXX_XXXX
260271
//xxx("blah");
261272
// The method xxx(String, int) is undefined for the type Temporary_XXXX_XXXX

0 commit comments

Comments
 (0)