Skip to content

Conversation

baweaver
Copy link

Fix Sum type to_s with Dry::Struct types

Fixes #482

Problem

Sum types composed of two Dry::Struct types raise NoMethodError: undefined method 'visit_sum_constructors' when calling to_s.

Solution

Added missing visit_sum_constructors method to the Printer class that recursively handles sum type printing by visiting left and right branches.

Changes

• Add visit_sum_constructors method that handles sum type decomposition
• Add visit_sum_constructor helper method for recursive sum type handling
• Add test coverage for sum types with Dry::Struct types

Testing

# This now works without error:
class A < Dry::Struct; end
class B < Dry::Struct; end

(A | B).to_s

Adds visit_sum_constructors method to Printer class that
recursively handles sum type printing without using private
method access.

Fixes dry-rb#482
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.

Sum type composed of two Dry::Struct raises NoMethodError visit_sum_constructors when calling to_s
1 participant