{"record":{"id":"2d38466d9e5815e6","repo":"gleam-lang/gleam","slug":"errortype-typedoesnotallowsize-type-type-label","errorCode":null,"errorMessage":"ErrorType::TypeDoesNotAllowSize { type_: type_.label() }","messagePattern":"ErrorType::TypeDoesNotAllowSize (.+?)","errorType":"validation","errorClass":"ErrorType","httpStatus":null,"severity":"error","filePath":"compiler-core/src/bit_array.rs","lineNumber":291,"sourceCode":"        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            );\n        }\n\n        _ => {}\n    }\n\n    // if unit specified, size must be specified\n    if let SegmentOptionCategories {\n        unit: Some(unit),\n        size: None,\n        ..\n    } = categories\n    {\n        return err(ErrorType::UnitMustHaveSize, unit.location());","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/bit_array.rs#L273-L309","documentation":"Unicode string segments (`utf8`, `utf16`, `utf32` and `_codepoint` variants) cannot have an explicit numeric `size` option. When `type_options` sees a segment whose type passes `is_unicode` and that carries a `size` option, it raises this error at the size option's location, reporting the type's label.","triggerScenarios":"Writing `<<name:utf8-size(10)>>` or `<<s:utf16-size(2)>>` — any unicode-typed segment (expression or pattern) specifying `size(N)` or a size expression.","commonSituations":"Assuming utf8 segments are byte-sized like in other languages; copying size options from binary/integer segments onto string segments.","solutions":["Remove the `size` option from the unicode segment.","Validate string length before constructing the bit array if a fixed-width string is required.","Use a non-unicode bytes segment with explicit encoding via `gleam/bit_array` when exact sizing is needed."],"exampleFix":"// before\nlet a = <<name:utf8-size(10)>>\n// after\nlet a = <<name:utf8>>","handlingStrategy":"validation","validationCode":"// Unicode segments take no explicit size option.\nfn unicode_size_forbidden(t: String, has_size: Bool) -> Bool {\n  let is_unicode = [\"Utf8\", \"Utf16\", \"Utf32\"] |> list.contains(t)\n  is_unicode && has_size\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never write `size(...)` on utf8/utf16/utf32 segments.","Validate string lengths in application code if fixed-width strings are needed.","Encode to bytes manually via `gleam/bit_array` when exact byte control is required."],"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"}