Skip to content

fix(generator): reject type names that shadow build-in types - #327

Merged
Bergmann89 merged 1 commit into
masterfrom
fix/shadowed-build-in-types
Nov 12, 2026
Merged

Bergmann89 merged 1 commit into
masterfrom
fix/shadowed-build-in-types

Conversation

@Bergmann89

Copy link
Copy Markdown
Owner

Unless GeneratorFlags::BUILD_IN_ABSOLUTE_PATHS is set, the generated code refers to build-in types and traits like String, Option or Result by their bare name. A generated type with the same name shadows them and the generated code does not compile, e.g.:

The generator now raises GeneratorError::ShadowedBuildIn for these names, which names the affected type and points to BUILD_IN_ABSOLUTE_PATHS, instead of silently generating broken code.

Changes

  • New error variant ShadowedBuildIn in the generator error (additive).
  • The check lives in claim_path, next to the existing DuplicateTypeName check, and is skipped when BUILD_IN_ABSOLUTE_PATHS is set.
  • New feature test shadowed_build_in: error for an element named Option, error for xs:string with an empty type postfix, and a compiled quick-xml snapshot with the flag enabled.

Schemas that generate one of these names without the flag now fail with an error instead of generating code that does not compile.

Checklist

  • Tests for the change (a bug fix has a test that fails without the fix)
  • Changed snapshots are regenerated with update-expectations and reviewed
  • cargo fmt, cargo clippy and cargo test pass (see CONTRIBUTING.md)
  • Breaking changes of the public API or the generated code are described above

Unless `BUILD_IN_ABSOLUTE_PATHS` is set, the generated code refers to
build-in types and traits like `String`, `Option` or `Result` by their bare
name. A generated type with the same name shadows them, which results in
code that does not compile, e.g. `pub type String = String;` for `xs:string`
with an empty type postfix, or broken `Option<..>` fields for an element
named `Option` (the element postfix is empty by default).

Raise an error that names the type and points to the flag instead of
silently generating broken code.
@Bergmann89
Bergmann89 force-pushed the fix/shadowed-build-in-types branch from 4b6720b to d86223f Compare November 12, 2026 20:29
@Bergmann89
Bergmann89 merged commit 56d85fe into master Nov 12, 2026
2 checks passed
@Bergmann89
Bergmann89 deleted the fix/shadowed-build-in-types branch November 12, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant