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

AST compiling failling with an array without member rules #95

Closed
mrbongiolo opened this issue May 27, 2016 · 3 comments
Closed

AST compiling failling with an array without member rules #95

mrbongiolo opened this issue May 27, 2016 · 3 comments
Labels

Comments

@mrbongiolo
Copy link

Falling AST:

ast = [
      :type, [
        "hash", [
          :schema, [
            [:key, [:skills, [:type, "array"]]]
          ]
        ]
      ]
    ]

This fails because visit_array tries to define a member rule every time, even when they don't exist.

I did some small tests and this seemed to solve the issue:

def visit_array(node)
  if node
    registry['array'].member(call(node))
  else
    registry['array']
  end
end

But I'm not sure if this would impact other usages of the AST with an array.

This is basically needed for schema validations that are done like that: required(:skills).filled(:array?), in which we just want to ensure that the key has an array, but the values inside of it doesn't matter.

Related: dry-rb/dry-validation#170

@solnic
Copy link
Member

solnic commented May 28, 2016

We should handle this use case, but I gotta ask - why the array elements "don't matter"? What I'm trying to do with these libs is to make people concious about type safety in a rather strict way. If you're using these libs to handle input from "the outside world" then you should be conservative about type expectations. I also understand that these libs might be used in contexts where less strict approach is fine, so I'm wondering what's your use case now :)

@solnic solnic added the bug label May 28, 2016
@mrbongiolo
Copy link
Author

I was thinking about that too, I think that we will always care about the contents of an array in some way. My real use case was that each itself wasn't checking before hand if something was an array and blew up when calling map, that's why I wanted to set the :array? rule there, but it then throw that error.

Maybe we should raise a more meaningful exception when someone is trying to use :array? without member rules? Or just let it be?

@solnic
Copy link
Member

solnic commented Jul 13, 2016

This is now fixed in master. I'll push 0.8.1 later today.

@solnic solnic closed this as completed Jul 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants