apple/pkl · error · VmTypeMismatchException.Simple

VmTypeMismatchException.Simple (value is not an Int)

Error message

VmTypeMismatchException.Simple (value is not an Int)

What it means

IntTypeAliasTypeNode checks that a value assigned to the `Int` typealias is actually an Int. If the value is not an integer at all (and any constraint check earlier already handled constrained failures), it throws VmTypeMismatchException.Simple with BaseModule.getIntClass(), i.e. 'expected Int, got <other type>'.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java:2546

    IntMaskSlotTypeNode(long mask) {
      super(VmUtils.unavailableSourceSection());
      this.mask = mask;
    }

    @Override
    protected final Object executeLazily(VirtualFrame frame, Object value) {
      var typealias = getVmTypeAlias();
      assert typealias != null;
      if (value instanceof Long l) {
        if ((l & mask) == l) return value;

        CompilerDirectives.transferToInterpreterAndInvalidate();
        var sourceSection = typealias.getConstraintSection();
        throw constraintException(value, sourceSection);
      }

      throw new VmTypeMismatchException.Simple(
          typealias.getBaseTypeSection(), value, BaseModule.getIntClass());
    }

    @Override
    public final VmClass getVmClass() {
      return BaseModule.getIntClass();
    }

    @Override
    public final VmTyped getMirror() {
      return MirrorFactories.typeAliasTypeFactory.create(this);
    }

    @Override
    public final boolean doIsEquivalentTo(TypeNode other) {
      return other instanceof IntMaskSlotTypeNode typeNode && mask == typeNode.mask;
    }

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Convert the value to an Int in Pkl: use `.toInt()` for strings/floats, or write the literal without a decimal point.
  2. Change the annotation to `Number` (or `Int|Float`) if the value may legitimately be fractional.
  3. Fix the upstream producer to emit an integer.

Example fix

// before
port: Int = "8080"
// after
port: Int = "8080".toInt()
Defensive patterns

Strategy: validation

Validate before calling

// Pkl: coerce before assigning to Int
port: Int = (externalValue as String).toInt()

Type guard

value is Int

Prevention

When it happens

Trigger: A property or expression typed `Int` receives a Float, String, Boolean, or other non-Int value; e.g. `port: Int = "8080"` or `port: Int = 8080.0`.

Common situations: Numbers parsed from JSON/YAML/CLI input arrive as strings or floats; Pkl `Number` literals with decimal points; unquoted config values that render as strings.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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