{"record":{"id":"b2bbb833717df6c9","repo":"apple/pkl","slug":"vmtypemismatchexception-simple-value-is-not-an-in-b2bbb8","errorCode":null,"errorMessage":"VmTypeMismatchException.Simple (value is not an Int8 in range)","messagePattern":"VmTypeMismatchException\\.Simple \\(value is not an Int8 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":2615,"sourceCode":"    }\n  }\n\n  public static final class Int8TypeAliasTypeNode extends IntSlotTypeNode {\n    public Int8TypeAliasTypeNode() {\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.byteValue()) return value;\n\n        CompilerDirectives.transferToInterpreterAndInvalidate();\n        var sourceSection = BaseModule.getInt8TypeAlias().getConstraintSection();\n        throw constraintException(value, sourceSection);\n      }\n\n      throw new VmTypeMismatchException.Simple(\n          BaseModule.getInt8TypeAlias().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.getInt8TypeAlias();\n    }\n\n    @Override\n    public VmTyped getMirror() {\n      return MirrorFactories.typeAliasTypeFactory.create(this);\n    }\n","sourceCodeStart":2597,"sourceCodeEnd":2633,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L2597-L2633","documentation":"Int8TypeAliasTypeNode checks the `Int8` typealias: the value must be an Int (vmClass is Int) whose value fits in the 8-bit signed range (-128..127). If it is not an in-range Int8, VmTypeMismatchException.Simple is thrown with the typealias's base-type section; out-of-range values that pass the base check are rejected by the constraint with constraintException.","triggerScenarios":"A property typed `Int8` receives a value that is not an Int, or an Int outside -128..127 (e.g. `tiny: Int8 = 300`, or `tiny: Int8 = \"5\"`).","commonSituations":"Ports, flags, or byte-sized fields set with values larger than 127; copying an ordinary Int into an Int8 field; string inputs from config files.","solutions":["Use a value within -128..127, or clamp/convert: `value.coercedIn(-128, 127)` or `.toInt()` for strings.","Widen the annotation to `Int`, `Int16`, `Int32`, or `Int` if the range is too small.","Validate the input range at the boundary where the value enters the module."],"exampleFix":"// before\nlevel: Int8 = 300\n// after\nlevel: Int8 = 100","handlingStrategy":"validation","validationCode":"// Pkl: range-check before assigning to Int8\nfunction toInt8(v: Int): Int8 =\n  if (v.isBetween(-128, 127)) v else throw(\"Int8 out of range: \\(v)\")","typeGuard":"value is Int && value >= -128 && value <= 127","tryCatchPattern":null,"preventionTips":["Clamp external values with .coercedIn(-128, 127).","Choose Int16/Int32/Int when the field can exceed byte range.","Add constraint properties to fail with domain-specific messages."],"tags":["pkl","type-mismatch","int8","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"}