{"record":{"id":"6138219aa8361933","repo":"apple/pkl","slug":"vmtypemismatchexception-simple-value-is-not-an-in-613821","errorCode":null,"errorMessage":"VmTypeMismatchException.Simple (value is not an Int16 in range)","messagePattern":"VmTypeMismatchException\\.Simple \\(value is not an Int16 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":2660,"sourceCode":"    }\n  }\n\n  public static final class Int16TypeAliasTypeNode extends IntSlotTypeNode {\n    public Int16TypeAliasTypeNode() {\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.shortValue()) return value;\n\n        CompilerDirectives.transferToInterpreterAndInvalidate();\n        var sourceSection = BaseModule.getInt16TypeAlias().getConstraintSection();\n        throw constraintException(value, sourceSection);\n      }\n\n      throw new VmTypeMismatchException.Simple(\n          BaseModule.getInt16TypeAlias().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.getInt16TypeAlias();\n    }\n\n    @Override\n    public VmTyped getMirror() {\n      return MirrorFactories.typeAliasTypeFactory.create(this);\n    }\n","sourceCodeStart":2642,"sourceCodeEnd":2678,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L2642-L2678","documentation":"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.","triggerScenarios":"A property typed `Int16` receives a non-Int value or an Int outside -32768..32767 (e.g. `medium: Int16 = 100000`).","commonSituations":"IDs, sizes, or thresholds that exceed 16-bit range; values computed at evaluation time overflowing the range; string inputs from external data.","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."],"exampleFix":"// before\nsize: Int16 = 100000\n// after\nsize: Int32 = 100000","handlingStrategy":"validation","validationCode":"// Pkl: range-check before assigning to Int16\nfunction toInt16(v: Int): Int16 =\n  if (v.isBetween(-32768, 32767)) v else throw(\"Int16 out of range: \\(v)\")","typeGuard":"value is Int && value >= -32768 && value <= 32767","tryCatchPattern":null,"preventionTips":["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."],"tags":["pkl","type-mismatch","int16","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"}