{"record":{"id":"06a2ff83e3cec924","repo":"BoundaryML/baml","slug":"encountered-impossible-type-expression-declaration-during","errorCode":null,"errorMessage":"Encountered impossible type_expression declaration during parsing","messagePattern":"Encountered impossible type_expression declaration during parsing","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/ast/src/parser/parse_type_expression_block.rs","lineNumber":169,"sourceCode":"                    FieldType::Symbol(FieldArity::Required, name.clone().unwrap(), None);\n            }\n        }\n    }\n\n    match name {\n        Some(name) => TypeExpressionBlock {\n            name,\n            fields,\n            methods,\n            input,\n            attributes,\n            documentation: doc_comment.and_then(|c| parse_comment_block(c, diagnostics)),\n            span: diagnostics.span(pair_span),\n            sub_type: sub_type.0,\n            type_span: diagnostics.span(sub_type.1),\n            is_dynamic_type_def,\n        },\n        _ => panic!(\"Encountered impossible type_expression declaration during parsing\"),\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use internal_baml_diagnostics::{Diagnostics, SourceFile};\n    use pest::{consumes_to, fails_with, parses_to, Parser};\n\n    use super::*;\n    use crate::parser::{BAMLParser, Rule};\n\n    #[test]\n    fn keyword_name_mandatory_whitespace() {\n        // This is the expected form.\n        parses_to! {\n            parser: BAMLParser,\n            input: \"class Foo {}\",\n            rule: Rule::type_expression_block,","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/ast/src/parser/parse_type_expression_block.rs#L151-L187","documentation":"A panic in parse_type_expression_block when the parsed declaration node is neither of the two expected type-expression declaration shapes (e.g. class-like vs enum-like sub_type). The final _ arm calls panic!(\"Encountered impossible type_expression declaration during parsing\"), signaling the grammar produced a declaration variant the parser does not know — a grammar/parser desync bug.","triggerScenarios":"parse_type_expression_block handling a type_expression pair whose inner rule does not match any of the destructured alternatives — typically after adding a new declaration kind to the grammar without extending this match.","commonSituations":"Seen when new BAML type declaration syntax (e.g. new schema block kinds) is added to the .pest grammar but parse_type_expression_block is not updated, or with hand-built parse trees in tests.","solutions":["Check the declaration syntax at the reported span in your .bml file and use a supported block form (class/enum style)","Report the input to the BAML repo — the match needs a new arm for the unrecognized declaration rule","Pin a BAML version where the declaration grammar is fully covered by this parser","If extending the grammar, add the corresponding match arm in parse_type_expression_block"],"exampleFix":"// before\nschemablock Foo { x: string }  // unsupported kind\n// after\nclass Foo { x string }","handlingStrategy":"validation","validationCode":"// Only parse known declaration block kinds\nconst KNOWN: &[&str] = &[\"class\", \"enum\", \"type\"];\nfn known_blocks(src: &str) -> bool {\n    src.lines().filter(|l| l.trim().contains(char::is_whitespace))\n        .all(|l| KNOWN.iter().any(|k| l.trim_start().starts_with(k)))\n}","typeGuard":"fn is_supported_declaration(kind: &str) -> bool {\n    matches!(kind, \"class\" | \"enum\" | \"type\")\n}","tryCatchPattern":"std::panic::catch_unwind(|| parse_type_expression_block(pair, doc, sub_type, dynamic, &mut diagnostics))\n    .map_err(|_| diagnostics.push(\"unknown type_expression declaration rule\"));","preventionTips":["Stick to documented block kinds (class/enum/type) in .bml files","Add a match arm whenever a new declaration kind is added to the grammar","Run the parser's cfg(test) suite (see the tests module in the same file) after grammar edits","Pin BAML versions and re-validate .bml files after upgrades"],"tags":["parser","rust","panic","grammar","internal-bug"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}