apple/pkl · error
integerOverflow
integerOverflow
Error message
integerOverflow
What it means
Pkl's `*` operator on two Ints uses StrictMath.multiplyExact and throws `integerOverflow` when the product exceeds the signed 64-bit Long range. Pkl never wraps integer multiplication silently. Reported at the multiplication expression in Pkl source.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/binary/MultiplicationNode.java:36
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.source.SourceSection;
import org.pkl.core.runtime.*;
@NodeInfo(shortName = "*")
public abstract class MultiplicationNode extends BinaryExpressionNode {
protected MultiplicationNode(SourceSection sourceSection) {
super(sourceSection);
}
@Specialization
protected long eval(long left, long right) {
try {
return StrictMath.multiplyExact(left, right);
} catch (ArithmeticException e) {
CompilerDirectives.transferToInterpreter();
throw exceptionBuilder().evalError("integerOverflow").build();
}
}
@Specialization
protected double eval(long left, double right) {
return left * right;
}
@Specialization
protected double eval(double left, long right) {
return left * right;
}
@Specialization
protected double eval(double left, double right) {
return left * right;
}
View on GitHub (pinned to f3efcbfc9b)
Solutions
- Convert to Float/Double (`a.toDouble() * b`) when approximate results are fine
- Reduce factor magnitudes or restructure the math
- Perform the computation in a language/runtime with big integers and pass the result in as a String
Example fix
// before (Pkl) val bytes = 3037000500 * 3037000500 // after val bytes = 3037000500.0 * 3037000500.0
Defensive patterns
Strategy: try-catch
When it happens
Trigger: `left * right` where both are Int and the product is outside [-2^63, 2^63-1], e.g. `3037000500 * 3037000500`.
Common situations: Computing byte sizes, combinatorial counts, or squared values in size estimation code with large config numbers.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- integerOverflow
- integerOverflow
- integerOverflow
- integerOverflow
- Cannot convert pkl.base#Int `%s` to java.lang.Byte because i
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/914bf68577ffcb4f.
Report an issue: GitHub.