Skip to content

Conversation

@coenttb
Copy link
Contributor

@coenttb coenttb commented Jul 27, 2025

Summary

  • Adds support for using throwing initializers with .memberwise conversions
  • Uses @_disfavoredOverload to maintain backward compatibility
  • Implements ThrowingMemberwise struct that properly propagates errors during parsing
  • Includes comprehensive tests for both throwing and non-throwing scenarios

Changes

  • Extended .memberwise API: Added overload that accepts @escaping (Values) throws -> Struct initializers
  • New ThrowingMemberwise struct: Handles throwing initializers while preserving all existing safety checks and memory layout validation
  • Comprehensive tests: Added MemberwiseTests.swift with coverage for both success and error cases
  • Backward compatibility: Existing non-throwing .memberwise usage remains unchanged

Test Plan

  • All existing tests pass (253 tests)
  • New tests verify throwing memberwise functionality works correctly
  • Non-throwing memberwise still works as expected
  • Throwing initializers properly propagate errors during parsing
  • Build succeeds without warnings

Implementation Details

The solution uses @_disfavoredOverload on the throwing overload to resolve compiler ambiguity, ensuring the non-throwing version is preferred when both signatures are compatible. The ThrowingMemberwise struct mirrors the original Memberwise implementation but with a throwing apply method that calls try self.initializer(input).

- Add @_disfavoredOverload memberwise overload for throwing initializers
- Implement ThrowingMemberwise struct with proper error propagation
- Add comprehensive tests for both throwing and non-throwing cases
- Maintain backward compatibility and all existing safety checks
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