Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug with array, struct and sum of structs in try method #462

Open
pyromaniac opened this issue Oct 4, 2023 · 0 comments
Open

A bug with array, struct and sum of structs in try method #462

pyromaniac opened this issue Oct 4, 2023 · 0 comments

Comments

@pyromaniac
Copy link

pyromaniac commented Oct 4, 2023

Describe the bug

Hi there, I found a couple of bugs working with structs and types in try method

To Reproduce

struct = Dry::Struct(id: Types::Integer)
type = Types::Array.of(struct)
# => #<Dry::Types[Constrained<Array<#<Class:0x0000000114d33398>> rule=[type?(Array)]>]>
type.try([{}])
# ArgumentError: error must be a CoercionError
# from /Users/pyromaniac/.rvm/gems/ruby-3.1.4@bookingsync/gems/dry-types-1.7.1/lib/dry/types/nominal.rb:122:in `failure'
# type.try([{id: 1}])
# => #<Dry::Types::Result::Success input=[#<#<Class:0x0000000114d33398> id=1>]>
type.try([struct.new(id: 1)])
# => #<Dry::Types::Result::Success input=[#<#<Class:0x0000000114d33398> id=1>]>
struct2 = Dry::Struct(id2: Types::Integer)
# => #<Class:0x0000000114f90c58>
type = Types::Array.of(struct | struct2)


# Btw, the inspection is also weird here
# => #<Dry::Types::Constrained:0x163b4>
type.try([{}])
# ArgumentError: error must be a CoercionError
# from /Users/pyromaniac/.rvm/gems/ruby-3.1.4@bookingsync/gems/dry-types-1.7.1/lib/dry/types/nominal.rb:122:in `failure'
type.try([{id: 1}])
# => #<Dry::Types::Result::Success input=[#<#<Class:0x0000000114d33398> id=1>]>
type.try([struct.new(id: 1)])
# NoMethodError: undefined method `input' for #<#<Class:0x0000000114d33398> id=1>
#
#               output << r.input unless Undefined.equal?(r.input)
#                                                         ^^^^^^
# from .rvm/gems/ruby-3.1.4/gems/dry-types-1.7.1/lib/dry/types/array/member.rb:79:in `block in try'

Expected behavior

No errors are expected for those 2 cases.

My environment

  • Affects my production application: YES
  • Ruby version: 3.1.4
  • OS: OS X/Ubuntu
  • Ruby: 3.1.4
  • dry-types: 1.7.1
  • dry-struct: 1.6.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant