{"record":{"id":"17cf2c76bedebf77","repo":"apple/pkl","slug":"vmtypemismatchexception-simple-value-is-not-an-in-17cf2c","errorCode":null,"errorMessage":"VmTypeMismatchException.Simple (value is not an Int32 in range)","messagePattern":"VmTypeMismatchException\\.Simple \\(value is not an Int32 in range\\)","errorType":"exception","errorClass":"VmTypeMismatchException.Simple","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":2705,"sourceCode":"    }\n  }\n\n  public static final class Int32TypeAliasTypeNode extends IntSlotTypeNode {\n    public Int32TypeAliasTypeNode() {\n      super(VmUtils.unavailableSourceSection());\n    }\n\n    @Override\n    protected Object executeLazily(VirtualFrame frame, Object value) {\n      if (value instanceof Long l) {\n        if (l == l.intValue()) return value;\n\n        CompilerDirectives.transferToInterpreterAndInvalidate();\n        throw constraintException(value, BaseModule.getInt32TypeAlias().getConstraintSection());\n      }\n\n      CompilerDirectives.transferToInterpreterAndInvalidate();\n      throw new VmTypeMismatchException.Simple(\n          BaseModule.getInt32TypeAlias().getBaseTypeSection(), value, BaseModule.getIntClass());\n    }\n\n    @Override\n    public VmClass getVmClass() {\n      return BaseModule.getIntClass();\n    }\n\n    @Override\n    public VmTypeAlias getVmTypeAlias() {\n      return BaseModule.getInt32TypeAlias();\n    }\n\n    @Override\n    public VmTyped getMirror() {\n      return MirrorFactories.typeAliasTypeFactory.create(this);\n    }\n","sourceCodeStart":2687,"sourceCodeEnd":2723,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L2687-L2723","documentation":"Int32TypeAliasTypeNode checks the `Int32` typealias: the value must be an Int within -2147483648..2147483647. Values that pass the base Int check but fail the range constraint raise the typealias's constraint exception; values that are not in-range Int32s at all raise VmTypeMismatchException.Simple with the base type section (vmClass Int).","triggerScenarios":"A property typed `Int32` receives a non-Int value, or an Int outside 32-bit range such as `big: Int32 = 5000000000` (Pkl Ints are arbitrary precision, so overflow is possible).","commonSituations":"Timestamps in nanoseconds, byte offsets, or hashes exceeding 2^31-1 assigned to Int32 fields; interop boundaries where the target system expects 32-bit integers.","solutions":["Use a value within the 32-bit range, or switch the annotation to `Int`.","Convert string inputs with `.toInt()` before assignment.","If 32-bit width is required (e.g. for external encoding), clamp or reject oversized values explicitly."],"exampleFix":"// before\noffset: Int32 = 5000000000\n// after\noffset: Int = 5000000000","handlingStrategy":"validation","validationCode":"// Pkl: range-check before assigning to Int32\nfunction toInt32(v: Int): Int32 =\n  if (v.isBetween(-2147483648, 2147483647)) v else throw(\"Int32 out of range: \\(v)\")","typeGuard":"value is Int && value >= -2147483648 && value <= 2147483647","tryCatchPattern":null,"preventionTips":["Remember Pkl Ints are arbitrary precision; Int32 fields can overflow.","Use plain Int unless a downstream system requires 32-bit width.","Validate timestamps/offsets against Int32 range when interoperating."],"tags":["pkl","type-mismatch","int32","value-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}