mirror of
https://github.com/apple/pkl.git
synced 2026-07-10 15:12:43 +02:00
Catch correct exception type in MultiplicationNode (#1652)
Closes #1651
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,7 @@ public abstract class MultiplicationNode extends BinaryExpressionNode {
|
||||
protected long eval(long left, long right) {
|
||||
try {
|
||||
return StrictMath.multiplyExact(left, right);
|
||||
} catch (VmException e) {
|
||||
} catch (ArithmeticException e) {
|
||||
CompilerDirectives.transferToInterpreter();
|
||||
throw exceptionBuilder().evalError("integerOverflow").build();
|
||||
}
|
||||
|
||||
@@ -202,6 +202,17 @@ examples {
|
||||
1 ** math.minInt
|
||||
-1 ** math.minInt
|
||||
|
||||
math.maxInt ** 0
|
||||
math.maxInt ** 1
|
||||
|
||||
4 ** 3 ** 2 == 4 ** (3 ** 2)
|
||||
1 + 2 ** 3 == 1 + (2 ** 3)
|
||||
2 * 2 ** 3 == 2 * (2 ** 3)
|
||||
2 ** 3 + 1 == (2 ** 3) + 1
|
||||
2 ** 3 * 2 == (2 ** 3) * 2
|
||||
}
|
||||
|
||||
["integer overflow"] {
|
||||
module.catch(() -> 2 ** math.maxInt8)
|
||||
module.catch(() -> 2 ** math.maxInt16)
|
||||
module.catch(() -> 2 ** math.maxInt32)
|
||||
@@ -210,15 +221,9 @@ examples {
|
||||
module.catch(() -> -2 ** math.maxInt16)
|
||||
module.catch(() -> -2 ** math.maxInt32)
|
||||
module.catch(() -> -2 ** math.maxInt)
|
||||
|
||||
math.maxInt ** 0
|
||||
math.maxInt ** 1
|
||||
module.catch(() -> math.maxInt ** 2)
|
||||
|
||||
4 ** 3 ** 2 == 4 ** (3 ** 2)
|
||||
1 + 2 ** 3 == 1 + (2 ** 3)
|
||||
2 * 2 ** 3 == 2 * (2 ** 3)
|
||||
2 ** 3 + 1 == (2 ** 3) + 1
|
||||
2 ** 3 * 2 == (2 ** 3) * 2
|
||||
module.catch(() -> math.maxInt * 2)
|
||||
module.catch(() -> math.maxInt + 2)
|
||||
module.catch(() -> math.minInt - 2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,21 +149,26 @@ examples {
|
||||
Infinity
|
||||
1.0
|
||||
1.0
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
1
|
||||
9223372036854775807
|
||||
"Integer overflow."
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
}
|
||||
["integer overflow"] {
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
"Integer overflow."
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user