-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Built-in type struct is incorrectly defined #4915
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
I think we can have conditional type for structs based on the Erlang version. If there's agreement on this, I can look into implementing it. |
Thanks for the great report @margnus1. |
I'm going to try re-enabling some of those mentioned tests as well now. |
Yep, I fixed up that type and re-enabled the test, PR incoming. |
Should be fixed in 433ff88. |
Closes #4915. Signed-off-by: José Valim <[email protected]>
@josevalim With the platform specific defines is there a chance an elixir build with OTP 19 will not work on OTP 18? Do we want this guarantee and have we followed it in the past? I think 19 itself is backwards compatible with 18 unless you use 19 specific features. |
The type of the
struct
built-in type is, as defined inlib/elixir/src/elixir.erl
,#{'__struct__' => atom()}
. This type does not match any struct values, however, as all structs contain keys that are not:__struct__
, and as of OTP 19 Dialyzer is capable of recognising this, causing spurious warnings for Elixir projects that use thestruct
type.A correct definition would be
#{'__struct__' := atom(), atom() => any()}
. If OTP 17&18 compatibility is required, the much weaker variant#{'__struct__' => atom(), atom() => any()}
can be used, but I would implore the Elixir team to use version detection in order to get the stronger variant when compiled with OTP 19, as the weaker variant is almost indistinguishable from#{atom() => any()}
.The problematic type seems to have also propagated to
Exception.t
, causing one of the two test failures inKernel.DialyzerTest
, (number 4 as reported in #4851).Environment
Current behavior
Dialyzing the following module yields a dialyzer warning on
good/0
, but not onbad/0
.Expected behavior
A dialyzer warning on
bad/0
, no warnings ongood/0
.The text was updated successfully, but these errors were encountered: