{"record":{"id":"474715e8bf90bb96","repo":"gleam-lang/gleam","slug":"errortype-typedoesnotallowunit-type-type-label","errorCode":null,"errorMessage":"ErrorType::TypeDoesNotAllowUnit { type_: type_.label() }","messagePattern":"ErrorType::TypeDoesNotAllowUnit (.+?)","errorType":"validation","errorClass":"ErrorType","httpStatus":null,"severity":"error","filePath":"compiler-core/src/bit_array.rs","lineNumber":278,"sourceCode":"            ..\n        } => {\n            return err(\n                ErrorType::SignednessUsedOnNonInt { type_: opt.label() },\n                sign.location(),\n            );\n        }\n\n        _ => {}\n    }\n\n    // utf8, utf16, utf32 exclude unit and size\n    match categories {\n        SegmentOptionCategories {\n            type_: Some(type_),\n            unit: Some(unit),\n            ..\n        } if is_unicode(type_) => {\n            return err(\n                ErrorType::TypeDoesNotAllowUnit {\n                    type_: type_.label(),\n                },\n                unit.location(),\n            );\n        }\n\n        SegmentOptionCategories {\n            type_: Some(type_),\n            size: Some(size),\n            ..\n        } if is_unicode(type_) => {\n            return err(\n                ErrorType::TypeDoesNotAllowSize {\n                    type_: type_.label(),\n                },\n                size.location(),\n            );","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/bit_array.rs#L260-L296","documentation":"The `unit` option (a size multiplier) cannot be combined with unicode string segments (`utf8`, `utf16`, `utf32` and their `_codepoint` variants). `type_options` detects a unicode-typed segment (via `is_unicode`) that also carries a `unit` option and raises this error at the `unit` option's location.","triggerScenarios":"Writing `<<x:utf8-unit(2)>>` or `<<c:utf16_codepoint-unit(4)>>` — any unicode-typed segment with `unit(N)`, in an expression or a pattern.","commonSituations":"Trying to pad or control string segment widths the way integer segments are controlled; copying integer-segment option sets onto utf8 segments when migrating BEAM code.","solutions":["Remove the `unit(N)` option from the unicode segment.","Control string segment length with a `size` option instead, e.g. `<<x:utf8-size(4)>>`.","If byte-level control is needed, use a bytes segment and encode/decode explicitly with `gleam/bit_array`."],"exampleFix":"// before\nlet a = <<name:utf8-unit(2)>>\n// after\nlet a = <<name:utf8-size(4)>>","handlingStrategy":"validation","validationCode":"// Do not attach unit(N) to utf8/utf16/utf32 segments.\nlet is_unicode = fn(t: String) -> Bool {\n  [\"Utf8\", \"Utf16\", \"Utf32\", \"Utf8Codepoint\", \"Utf16Codepoint\", \"Utf32Codepoint\"]\n  |> list.contains(t)\n}\n// if is_unicode(t) { skip unit option }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use `unit` on unicode segments.","Use `size` (not `unit`) to control string segment length.","Check the segment type before copying option sets between segments."],"tags":["compiler","bit-array","type-error","gleam"],"backgroundTag":"mutually-exclusive-options","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"}