CargoSense / vex

Data Validation for Elixir
MIT License
595 stars 60 forks source link

Automatic generation of `Vex.Extract` protocol when using `Vex.Struct` appears broken in 1.14.1 #71

Closed darraghenright closed 1 year ago

darraghenright commented 1 year ago

Hi folks 👋

I hope all is well. The documentation suggests that protocols are automatically generated for structs when using Vex.Struct but this appears to be broken since 1.14.

I copy-pasted the example presented in the In Structs section of the README to reproduce:

  1. I created a vanilla mix project.
  2. I created a new file called user.ex and copy-pasted the User module from the example into it.
  3. I created a function called validate_user and added the usage example into it.
  4. I ran the command both via the command line with mix run -c and interactively in iex.

Findings:

The full error is:

(Protocol.UndefinedError) protocol Vex.Extract not implemented for %User{username: "actualuser", password: "abcdefghi", password_confirmation: "abcdefghi"} of type User (a struct). This protocol is implemented for the following type(s): Kernel, List, Map, Tuple
(vex 0.9.0) lib/vex/extract.ex:1: Vex.Extract.impl_for!/1
(vex 0.9.0) lib/vex/extract.ex:3: Vex.Extract.settings/1
(vex 0.9.0) lib/vex.ex:14: Vex.valid?/1

I had a look through the 1.14 changelog. Not much jumped out, the only thing I noticed was the following:

[Protocol] Expand :for in protocols with the appropriate env

I don't know if it's related. I'm still looking into that, and will update if I find out anything else.

darraghenright commented 1 year ago

A small update:

So clearly something changed after that release candidate.

darraghenright commented 1 year ago

Had a quick chat about this in Elixir Slack and turns out this was a bug in Elixir version 1.14.1 which was fixed in 1.14.2:

https://github.com/elixir-lang/elixir/issues/12186

I am happy to confirm that upgrading to 1.14.2 fixes the issue. Closing!

mudassirkhan19 commented 1 year ago

@darraghenright , looks like we are bumping into the same problems across projects 😄