{"record":{"id":"03ecdf7a03ef1688","repo":"gleam-lang/gleam","slug":"utf-codepoint-pattern-matching-is-not-supported","errorCode":null,"errorMessage":"UTF-codepoint pattern matching is not supported","messagePattern":"UTF-codepoint pattern matching is not supported","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/bit_array.rs","lineNumber":115,"sourceCode":"fn type_options<TypedValue>(\n    input_options: &[BitArrayOption<TypedValue>],\n    mode: TypeOptionsMode,\n    must_have_size: bool,\n    target: Target,\n) -> Result<Arc<Type>, Error>\nwhere\n    TypedValue: GetLiteralValue,\n{\n    use BitArrayOption::*;\n\n    let mut categories = SegmentOptionCategories::new();\n    // Basic category checking\n    for option in input_options {\n        match option {\n            Utf8Codepoint { .. } | Utf16Codepoint { .. } | Utf32Codepoint { .. }\n                if mode == TypeOptionsMode::Pattern && target == Target::JavaScript =>\n            {\n                return err(\n                    ErrorType::OptionNotSupportedForTarget {\n                        target,\n                        option: UnsupportedOption::UtfCodepointPattern,\n                    },\n                    option.location(),\n                );\n            }\n\n            Bytes { .. }\n            | Int { .. }\n            | Float { .. }\n            | Bits { .. }\n            | Utf8 { .. }\n            | Utf16 { .. }\n            | Utf32 { .. }\n            | Utf8Codepoint { .. }\n            | Utf16Codepoint { .. }\n            | Utf32Codepoint { .. } => {","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/bit_array.rs#L97-L133","documentation":"This Gleam compiler error occurs when a UTF codepoint segment option (utf8_codepoint, utf16_codepoint, or utf32_codepoint) is used inside a bit array PATTERN while compiling to JavaScript. The compiler's type_options function explicitly rejects this combination because codepoint pattern matching is not implemented on the JavaScript target.","triggerScenarios":"Compiling a bit array pattern segment that carries a Utf8Codepoint, Utf16Codepoint, or Utf32Codepoint option when Target::JavaScript is selected and mode is TypeOptionsMode::Pattern. The same options in a bit array value expression are fine.","commonSituations":"Cross-target projects that work on Erlang but fail when someone adds a JS target; developers porting binary-protocol parsing code (e.g. matching on UTF-8 string fragments) to JavaScript.","solutions":["Rewrite the pattern to match on the bit array as bytes/bits without a utf-codepoint option, and decode the codepoint manually in the branch body","Split target-specific code with conditional compilation or keep codepoint pattern matching in modules only compiled for Erlang","Use string pattern matching or a binary-to-string conversion before matching instead of codepoint-level bit array patterns"],"exampleFix":"// before (JS target)\nlet assert <<\"a\":utf8_codepoint, rest:bytes>> = data\n// after\nlet assert <<_, rest:bytes>> = data\nlet ch = bit_array.to_string(<<>>)\n// or restrict this module/function to the Erlang target","handlingStrategy":"validation","validationCode":"// Before using a utf-codepoint pattern option, check the target at build time\n// gleam: only use `utf8_codepoint`/`utf16_codepoint`/`utf32_codepoint` in patterns\n// when targeting erlang. For JS, guard with a runtime decode instead:\nfn uses_codepoint_patterns(target: String) -> Bool {\n  target != \"javascript\"\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `gleam build --target javascript` in CI alongside the Erlang build to catch target-incompatible features early","Isolate bit-array pattern matching in modules only imported by Erlang-target code","Prefer decoding to String then matching on strings for cross-target code"],"tags":["gleam","bit-array","javascript-target","pattern-matching"],"backgroundTag":"unsupported-operation","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}