Skip to content

Commit

Permalink
Add warning for integer literals not fitting into long
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Jul 25, 2017
1 parent f14e6c7 commit cd369ee
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/som/compiler/NumeralParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.math.BigInteger;

import som.VM;


public class NumeralParser {

Expand Down Expand Up @@ -88,7 +90,13 @@ private long calculateNumberWithRadixLong() {
v = c - 'A' + 10 /* A has value 10 */;
}

result = Math.addExact(result, (long) (Math.pow(r, length - i - 1) * v));
try {
result = Math.addExact(result, (long) (Math.pow(r, length - i - 1) * v));
} catch (ArithmeticException e) {
// TODO: need to overflow into BigInteger
VM.errorPrintln("Warning: Parsed Integer literal which did not fit into long. " + lexer.getCurrentLineNumber() + ":" + lexer.getCurrentColumn());
return result;
}
}
return result;
}
Expand Down

0 comments on commit cd369ee

Please sign in to comment.