-
Notifications
You must be signed in to change notification settings - Fork 3.4k
generated meta is not respected by new type system #13727
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
Comments
This code generates warning too defmodule Xxx do
defmacro f(x) do
quote generated: true do
unquote(x) < 2
end
|> Macro.prewalk(&Macro.update_meta(&1, fn x -> Keyword.put(x, :generated, true) end))
end
def g do
f(:x)
end
end |
This makes usage of any not type-correct macro broken with |
As discussed here, this has been a conscious decision to not ignore But I agree that while most type errors should have no false positives, this example sounds like one. |
This library https://hexdocs.pm/pathex/readme.html generates lenses from paths like Actually case x do
%{^a => y} ->
case y do
%{^b => z} ->
...
end
_ when is_list(x) and is_integer(a) and a >= 0 ->
at_index(x, a)
_ when is_list(x) and is_integer(a) and a < 0 ->
at_negative_index(x, a)
... # other clauses for tuples and keywords
end Pathex is capable of generation of paths for negative indexes index = -2
result = force_set!([0, 1, 2, 3, 4, 5, 6, 7], path(index), 123)
assert result == [0, 1, 2, 3, 4, 5, 123, 7] But on the moment of macro expansion, it is unable to detect the type of Therefore code like this key = :x
result = get(%{x: 123}, path(key))
assert result == 123 will emit a warning, because |
Thanks. Agreed those cases cannot be detected. We will start checking :generated soon. |
Uh oh!
There was an error while loading. Please reload this page.
Elixir and Erlang/OTP versions
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
Elixir 1.17.1 (compiled with Erlang/OTP 27)
Operating system
linux
Current behavior
Expected behavior
No warning produced
The text was updated successfully, but these errors were encountered: