{"record":{"id":"26cec3b7517a8e26","repo":"gleam-lang/gleam","slug":"errortype-conflictingunitoptions","errorCode":null,"errorMessage":"ErrorType::ConflictingUnitOptions","messagePattern":"ErrorType::ConflictingUnitOptions","errorType":"validation","errorClass":"ErrorType","httpStatus":null,"severity":"error","filePath":"compiler-core/src/bit_array.rs","lineNumber":192,"sourceCode":"                        },\n                        option.location(),\n                    );\n                } else {\n                    categories.endian = Some(option);\n                }\n            }\n\n            Size { .. } => {\n                if categories.size.is_some() {\n                    return err(ErrorType::ConflictingSizeOptions, option.location());\n                } else {\n                    categories.size = Some(option);\n                }\n            }\n\n            Unit { .. } => {\n                if categories.unit.is_some() {\n                    return err(ErrorType::ConflictingUnitOptions, option.location());\n                } else {\n                    categories.unit = Some(option);\n                }\n            }\n        }\n    }\n\n    // Some options are not allowed in value mode\n    if mode == TypeOptionsMode::Expression {\n        match categories {\n            SegmentOptionCategories {\n                signed: Some(opt), ..\n            }\n            | SegmentOptionCategories {\n                type_: Some(opt @ Bytes { .. }),\n                ..\n            } => return err(ErrorType::OptionNotAllowedInValue, opt.location()),\n            _ => (),","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/bit_array.rs#L174-L210","documentation":"ErrorType::ConflictingUnitOptions is raised when a bit array segment declares the unit option more than once. A segment accepts at most one 'unit:n' option, which defines the default unit size for the segment.","triggerScenarios":"Writing a segment like <<x:bytes-unit(8)-unit(1)>> or duplicating the unit option through generated/copy-pasted option lists; type_options finds categories.unit already set.","commonSituations":"Copy-paste of option chains between segments; templated code generation emitting unit twice; misunderstanding that unit multiplies with size and trying to stack two units.","solutions":["Keep only one unit option per segment","If you wanted a total size of size*unit, express that with a single size and single unit","Review generated option lists for duplicated unit emissions"],"exampleFix":"// before\n<<raw:bytes-unit(8)-unit(1)>>\n// after\n<<raw:bytes-unit(8)>>","handlingStrategy":"validation","validationCode":"// At most one `unit:` option per segment\nfn unit_option_count(spec: String) -> Int {\n  string.split(spec, \"unit:\") |> list.length |> int.subtract(1)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One unit per segment; combine with a single size to get the total","Check code generators that emit segment options for duplicated unit output","Keep option lists short and hand-reviewed per segment"],"tags":["gleam","bit-array","conflicting-options"],"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"}