Skip to content

Fully qualify stdlib types (Error, Encoder, Decoder) in generated code#869

Merged
czechboy0 merged 2 commits intoapple:mainfrom
william-laverty:fix/fully-qualify-stdlib-types
Mar 2, 2026
Merged

Fully qualify stdlib types (Error, Encoder, Decoder) in generated code#869
czechboy0 merged 2 commits intoapple:mainfrom
william-laverty:fix/fully-qualify-stdlib-types

Conversation

@william-laverty
Copy link
Copy Markdown
Contributor

Summary

Fixes generated code to emit Swift.Error, Swift.Encoder, and Swift.Decoder instead of unqualified Error, Encoder, and Decoder. This prevents compilation errors when user modules define their own types with those names.

Changes

Source changes

  • translateCodable.swift: Changed .member("Error").member(["Swift", "Error"]), .member("Encoder").member(["Swift", "Encoder"]), .member("Decoder").member(["Swift", "Decoder"])
  • translateBoxedTypes.swift: Same changes for boxed type Codable conformances

Test updates

  • Updated Petstore/Types.swift reference source to expect fully qualified types
  • Updated SnippetBasedReferenceTests.swift to match

Before / After

// Before
var errors: [any Error] = []
public init(from decoder: any Decoder) throws { ... }
public func encode(to encoder: any Encoder) throws { ... }

// After  
var errors: [any Swift.Error] = []
public init(from decoder: any Swift.Decoder) throws { ... }
public func encode(to encoder: any Swift.Encoder) throws { ... }

Closes #719

Copy link
Copy Markdown
Contributor

@czechboy0 czechboy0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @william-laverty 🙏

@czechboy0 czechboy0 enabled auto-merge (squash) February 26, 2026 09:30
@FranzBusch
Copy link
Copy Markdown
Member

We should probably think about generating code with full module qualifiers once 6.3 is released to avoid any ambiguity.

@czechboy0 czechboy0 added the 🔨 semver/patch No public API change. label Feb 26, 2026
@czechboy0
Copy link
Copy Markdown
Contributor

@william-laverty please rerun the formatter, the CI is failing on that

auto-merge was automatically disabled February 27, 2026 07:02

Head branch was pushed to by a user without write access

@czechboy0
Copy link
Copy Markdown
Contributor

I think you need to revert all those formatting changes, and then run the Swift 6.2-aligned swift-format using the act command in the CONTRIBUTING guide. That will skip the doc files and other files we don't want to reformat.

In other words, no files where you didn't change code should be modified in this PR.

@william-laverty william-laverty force-pushed the fix/fully-qualify-stdlib-types branch from f4bb630 to e1e6b12 Compare March 1, 2026 07:02
@william-laverty
Copy link
Copy Markdown
Contributor Author

Reverted all formatting-only changes — the diff now only touches files where code actually changed (the Swift. qualification in Sources + corresponding test expectations). Sorry about the noise from the earlier swift-format runs.

@czechboy0 czechboy0 enabled auto-merge (squash) March 2, 2026 07:26
@czechboy0 czechboy0 merged commit 026c362 into apple:main Mar 2, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fully qualify stdlib types in generated code

3 participants