-
Notifications
You must be signed in to change notification settings - Fork 13
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
Crash in Gradient.ElixirExpr.pp_guards #145
Comments
Hey, @lukaszsamson! Thanks for creating the ticket. It would help a lot if you could also attach the code the crash happens on. |
I cannot share the repo but I'll try to isolate it |
I've been trying to reproduce this error, but after trying a number of different combinations I still don't know what generates the guards we see in the error message. These guards check for an argument being an atom, but neither [
[
{:call, [generated: true, location: 21],
{:remote, [generated: true, location: 21],
{:atom, [generated: true, location: 21], :erlang},
{:atom, [generated: true, location: 21], :is_atom}},
[{:var, [generated: true, location: 21], :_@1}]},
{:op, [generated: true, location: 21], :"=/=",
{:var, [generated: true, location: 21], :_@1},
{:atom, [generated: true, location: 21], nil}},
{:op, [generated: true, location: 21], :"=/=",
{:var, [generated: true, location: 21], :_@1},
{:atom, [generated: true, location: 21], true}},
{:op, [generated: true, location: 21], :"=/=",
{:var, [generated: true, location: 21], :_@1},
{:atom, [generated: true, location: 21], false}}
]
] In general, when defining guards in Elixir we have to use the iex(1)> :merl.quote('fun (X) when X > 1 andalso X < 5 -> ok end')
{:fun, 1,
{:clauses,
[
{:clause, 1, [{:var, 1, :X}],
[
[
{:op, 1, :andalso, {:op, 1, :>, {:var, 1, :X}, {:integer, 1, 1}},
{:op, 1, :<, {:var, 1, :X}, {:integer, 1, 5}}}
]
], [{:atom, 1, :ok}]}
]}} We can see there's a single [
{:op, 1, :andalso, {:op, 1, :>, {:var, 1, :X}, {:integer, 1, 1}},
{:op, 1, :<, {:var, 1, :X}, {:integer, 1, 5}}}
] In Erlang it's possible to generate a list of guards by using the iex(2)> :merl.quote('fun (X) when X > 1, X < 5 -> ok end')
{:fun, 1,
{:clauses,
[
{:clause, 1, [{:var, 1, :X}],
[
[
{:op, 1, :>, {:var, 1, :X}, {:integer, 1, 1}},
{:op, 1, :<, {:var, 1, :X}, {:integer, 1, 5}}
]
], [{:atom, 1, :ok}]}
]}} This, in fact, generates a list of guards: [
{:op, 1, :>, {:var, 1, :X}, {:integer, 1, 1}},
{:op, 1, :<, {:var, 1, :X}, {:integer, 1, 5}}
] However, as far as I know, Elixir doesn't have an equivalent of Without a hint about what code leads to this error it's going to be quite hard to debug further :| |
The text was updated successfully, but these errors were encountered: