{"record":{"id":"5cb68c2e1224c287","repo":"BoundaryML/baml","slug":"float-literals-cannot-be-parsed","errorCode":null,"errorMessage":"Float literals cannot be parsed","messagePattern":"Float literals cannot be parsed","errorType":"error_code","errorClass":"ConvertError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_sap/src/sap_model/convert.rs","lineNumber":28,"sourceCode":"use ::sys_types::{ClassDefinition, DefKey, EnumDefinition, SapTy};\nuse indexmap::IndexMap;\n\nuse crate::sap_model::{\n    self, AnnotatedEnumVariant, AnnotatedField, AnnotatedTy, ArrayTy, AttrLiteral, BigintLiteralTy,\n    BigintTy, BoolLiteralTy, BoolTy, ClassTy, EnumTy, EnumVariantTy, FloatTy, IntLiteralTy, IntTy,\n    MapTy, MediaTy, NullTy, StringLiteralTy, StringTy, TyResolved, TyWithMeta, TypeAnnotations,\n    TypeRefDb, UnionTy,\n};\n\nimpl crate::sap_model::TypeIdent for DefKey {}\n\n#[derive(thiserror::Error, Debug)]\npub enum ConvertError {\n    #[error(\"Failed to parse float: {0}\")]\n    ParseFloat(#[from] std::num::ParseFloatError),\n    #[error(\"Unknown media kind\")]\n    UnknownMediaKind,\n    #[error(\"Float literals cannot be parsed\")]\n    FloatLiteral,\n    #[error(\"Non-parsable type: {0:?}\")]\n    NonParsableType(Box<SapTy>),\n    #[error(\"Unknown class: {0}\")]\n    UnknownClass(DefKey),\n    #[error(\"Unknown enum: {0}\")]\n    UnknownEnum(DefKey),\n    #[error(\"Unknown type alias: {0}\")]\n    UnknownTypeAlias(DefKey),\n    #[error(\"Unknown name (could not determine if it was a class, enum, or type alias): {0}\")]\n    UnknownName(DefKey),\n    #[error(\"Could not add a type to the database as the name `{0}` is already present\")]\n    AlreadyPresent(DefKey),\n    #[error(\"Recursion depth exceeded for {0}\")]\n    RecursionDepthExceeded(&'static str),\n    #[error(\"Unions must be flattened\")]\n    UnflattenedUnion,\n    /// Something like `type A = B; type B = A;` is invalid.","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_sap/src/sap_model/convert.rs#L10-L46","documentation":"`ConvertError::FloatLiteral` is thrown when the sap_model converter encounters a float literal in a position where floats cannot be represented — the target type model only supports integer literals, so any float literal is rejected outright.","triggerScenarios":"Converting a type expression (e.g. a numeric literal used as a type parameter or enum-ish literal type) that contains a non-integer float such as `1.5`, where the target type system only admits integer literals.","commonSituations":"Writing `type X = 1.5` style literal types in BLP source; passing float-typed config values where integer literal types are expected; porting code from a system that allowed float literal types.","solutions":["Replace the float literal with an integer literal in the source (e.g. `1` instead of `1.5`).","Check the language spec: float literal types are not supported; use a named float type or constraint instead.","If you maintain the converter, emit a better diagnostic pointing at the offending literal.","Use a range/validated string field instead of a literal type for non-integer values."],"exampleFix":"// before (BLP source)\ntype Threshold = 1.5;\n// after\ntype Threshold = 1; // integer literal types only","handlingStrategy":"validation","validationCode":"fn is_float_literal(s: &str) -> bool {\n    s.contains('.') || s.contains('e') || s.contains('E')\n}\n// reject float literals in integer-literal-type positions before conversion","typeGuard":null,"tryCatchPattern":"match convert(ty) {\n    Ok(m) => m,\n    Err(ConvertError::FloatLiteral) => { eprintln!(\"float literal types unsupported at {ty:?}\"); Err(MyErr::FloatLiteralType) }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Use only integer literals in literal-type positions.","Document that float literal types are unsupported in your BLP style guide.","Add a lint that flags `.`-containing literals used as types."],"tags":["rust","type-system","literals"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}