apple/pkl · error

integerOverflow

integerOverflow

Error message

integerOverflow

What it means

Pkl's Int is a 64-bit signed integer. Unary negation of an Int is performed with Math.negateExact; negating Long.MIN_VALUE (-9223372036854775808) has no positive counterpart, so VmSafeMath.negate throws the `integerOverflow` eval error instead of silently wrapping.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/runtime/VmSafeMath.java:38

import com.oracle.truffle.api.nodes.Node;
import java.math.RoundingMode;
import org.pkl.core.runtime.VmException.ProgramValue;
import org.pkl.core.util.MathUtils;

/**
 * Uses methods from [java.lang.(Strict)Math] where appropriate, which may benefit from special
 * optimization by Graal. To control error messages in a single place (namely here),
 * [ArithmeticException]s thrown by [java.lang.StrictMath] are caught and rethrown.
 */
public final class VmSafeMath {
  private VmSafeMath() {}

  public static long negate(long x) {
    try {
      return Math.negateExact(x);
    } catch (ArithmeticException e) {
      CompilerDirectives.transferToInterpreter();
      throw intOverflow();
    }
  }

  public static double negate(double x) {
    return -x;
  }

  public static long add(long x, long y) {
    try {
      return StrictMath.addExact(x, y);
    } catch (ArithmeticException e) {
      CompilerDirectives.transferToInterpreter();
      throw intOverflow();
    }
  }

  public static double add(double x, double y) {
    return x + y;

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Change the value to something within [-9223372036854775807, 9223372036854775807].
  2. If you need the magnitude of Long.MIN_VALUE, use a Float: `-(9223372036854775808.0.toFloat())`.
  3. Guard the negation: `if (x == Int.MIN_VALUE) ... else -x` and handle the extreme case explicitly.

Example fix

// before
abs = -x  // x == -9223372036854775808

// after
abs = if (x == Int.MIN_VALUE) 9223372036854775808.0.toFloat() else -x
Defensive patterns

Strategy: validation

Validate before calling

// Pkl
isSafeToNegate = (x: Int) -> x != Int.MIN_VALUE

Type guard

function isNegatable(x: Int): Boolean = x != Int.MIN_VALUE

Prevention

When it happens

Trigger: Evaluating the unary minus operator on Int value -9223372036854775808 (the only value whose negation overflows), e.g. `-x` where x == Long.MIN_VALUE, or `-(-9223372036854775808)`.

Common situations: Config arithmetic on extreme sentinel values (using Long.MIN_VALUE as 'unset'); large absolute values produced by earlier multiplication before negation.

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


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/b689a183aa32cce0. Report an issue: GitHub.