{"record":{"id":"154824bc573bf81b","repo":"gleam-lang/gleam","slug":"invalid-slice-type-made-it-to-code-generation-type","errorCode":null,"errorMessage":"invalid slice type made it to code generation: {type_:#?}","messagePattern":"invalid slice type made it to code generation: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/javascript/decision.rs","lineNumber":1808,"sourceCode":"                let start = self.offset_to_doc(arena, from, false);\n                let end = if from.is_zero() {\n                    size\n                } else {\n                    docvec![arena, start, SPACE_PLUS_SPACE_DOCUMENT, size]\n                };\n                (start, end)\n            };\n\n        match type_ {\n            ReadType::Int => {\n                self.bit_array_slice_to_int(arena, bit_array, start, end, endianness, *signed)\n            }\n            ReadType::Float => {\n                self.bit_array_slice_to_float(arena, bit_array, start, end, endianness)\n            }\n            ReadType::BitArray => self.bit_array_slice_with_end(arena, bit_array, from, end),\n            ReadType::String | ReadType::UtfCodepoint => {\n                panic!(\"invalid slice type made it to code generation: {type_:#?}\")\n            }\n        }\n    }\n\n    fn offset_to_doc(\n        &mut self,\n        arena: &'doc DocumentArena<'a, 'doc>,\n        offset: &Offset,\n        parenthesise: bool,\n    ) -> Document<'a, 'doc> {\n        if offset.is_zero() {\n            return ZERO_DOCUMENT;\n        }\n\n        let mut pieces = vec![];\n        if offset.constant != BigInt::ZERO {\n            pieces.push(eco_string_int(arena, offset.constant.to_string().into()));\n        }","sourceCodeStart":1790,"sourceCodeEnd":1826,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/javascript/decision.rs#L1790-L1826","documentation":"Panic in `read_action_to_doc` (compiler-core/src/javascript/decision.rs:1808) when a bit array slice's `ReadType` is `String` or `UtfCodepoint`. These segment types require specialized slicing (e.g. utf8 decoding/codepoint validation) that has no generic binary-slice implementation for JavaScript, so reaching them here indicates an unhandled segment type — an internal invariant violation during JS codegen.","triggerScenarios":"Compiling a JavaScript-target case on a bit array containing a `utf8` string or `utf_codepoint` segment whose slicing reaches the generic slice-to-doc helper instead of the dedicated string/codepoint path — due to a compiler bug or missing handling for these read types.","commonSituations":"Users matching on utf8 string or utf_codepoint segments in bit arrays when targeting JavaScript, on compiler versions lacking that codegen support; compiler contributors refactoring `read_action_to_doc`.","solutions":["Upgrade the gleam compiler — newer versions add dedicated slicing for string/utf-codepoint segments on the JS target.","Temporarily match on int/bit-array segments and validate/decode UTF-8 manually (e.g. via a helper) instead of `<<..:utf8>>` patterns.","Target Erlang for code relying on utf_codepoint/string bit array matching if the JS backend panics on your version.","File a bug with the pattern and target; contributors should extend `read_action_to_doc` to dispatch String/UtfCodepoint to dedicated helpers."],"exampleFix":"// before: utf8 segment panics in JS codegen (older compiler)\ncase bits { <<\"ok\":utf8>> <> rest -> .. }\n// after (workaround): match bytes as bits and compare\nlet <<first:bits-size(16), rest:bits>> = bits","handlingStrategy":"type-guard","validationCode":"match read_type {\n    ReadType::String | ReadType::UtfCodepoint => return Err(Error::UnsupportedSliceType),\n    _ => ok,\n}","typeGuard":"fn is_sliceable(t: &ReadType) -> bool {\n    !matches!(t, ReadType::String | ReadType::UtfCodepoint)\n}","tryCatchPattern":null,"preventionTips":["Route String/UtfCodepoint segments to dedicated slicing helpers before the generic path","Test JS codegen for utf8 and utf_codepoint bit array segments","On older compilers, avoid utf8/utf_codepoint matching when targeting JavaScript"],"tags":["panic","internal-invariant","javascript","bit-array","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"49f8762da595eb3c8f576656a4200a142ca188c9","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}