apple/pkl · error · VmTypeMismatchException.Simple
VmTypeMismatchException.Simple (value is not an Int16 in…
Error message
VmTypeMismatchException.Simple (value is not an Int16 in range)
What it means
Int16TypeAliasTypeNode checks the `Int16` typealias: the value must be an Int within the 16-bit signed range (-32768..32767). Non-Int values are rejected via VmTypeMismatchException.Simple using the typealias's base type section; out-of-range but integer values hit the constraint check instead.
Solutions
- Bring the value into -32768..32767 or convert strings with `.toInt()`.
- Widen the annotation to `Int32`, `Int`, or `Number` if larger values are valid.
- Add an `isBetween(-32768, 32767)` guard upstream to fail with a clearer message.
Example fix
// before size: Int16 = 100000 // after size: Int32 = 100000
Defensive patterns
Strategy: validation
Validate before calling
// Pkl: range-check before assigning to Int16
function toInt16(v: Int): Int16 =
if (v.isBetween(-32768, 32767)) v else throw("Int16 out of range: \(v)") Type guard
value is Int && value >= -32768 && value <= 32767
Prevention
- Validate computed values against the 16-bit range before assignment.
- Use Int32/Int for IDs and sizes that may exceed 32767.
- Test boundary values -32768 and 32767 in module tests.
When it happens
Trigger: A property typed `Int16` receives a non-Int value or an Int outside -32768..32767 (e.g. `medium: Int16 = 100000`).
Common situations: IDs, sizes, or thresholds that exceed 16-bit range; values computed at evaluation time overflowing the range; string inputs from external data.
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
- VmTypeMismatchException.Simple (value is not an Int32 in…
- VmTypeMismatchException.Simple (value is not an Int8 in…
- cannotExportValue
- cannotFlattenCollectionWithNonCollectionElement
- cannotIterateOverThisValue
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/6138219aa8361933.
Report an issue: GitHub.
Appendix: source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java:2660
}
}
public static final class Int16TypeAliasTypeNode extends IntSlotTypeNode {
public Int16TypeAliasTypeNode() {
super(VmUtils.unavailableSourceSection());
}
@Override
protected Object executeLazily(VirtualFrame frame, Object value) {
if (value instanceof Long l) {
if (l == l.shortValue()) return value;
CompilerDirectives.transferToInterpreterAndInvalidate();
var sourceSection = BaseModule.getInt16TypeAlias().getConstraintSection();
throw constraintException(value, sourceSection);
}
throw new VmTypeMismatchException.Simple(
BaseModule.getInt16TypeAlias().getBaseTypeSection(), value, BaseModule.getIntClass());
}
@Override
public VmClass getVmClass() {
return BaseModule.getIntClass();
}
@Override
public VmTypeAlias getVmTypeAlias() {
return BaseModule.getInt16TypeAlias();
}
@Override
public VmTyped getMirror() {
return MirrorFactories.typeAliasTypeFactory.create(this);
}
View on GitHub (pinned to f3efcbfc9b)