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
nfields
is easily misused and can lead to bugs
#29977
Comments
This is why there are doc strings. Ok to propose new names for these though, which can even be introduced in 1.x. |
Why not just delete |
That would prevent us from having variable length objects. |
Ah, I see. That makes sense. |
Are this kind of expando so common ? The only references to variable length objects i found in julia github were for |
Currently. |
TODO: learn to read docstrings See also JuliaLang/julia#29977
Here is a struct for a bitmap header
We want to compute the packed size (no padding) so we write something like
and it seems to work fine
There is however a terrible bug here which can be made obvious with:
😱 We are getting the number of fields inside the
DataType
object (which in this case happened to be the same number as the fields insideBitmapHeader
.) Adding fields toBitmapHeader
will now lead to (likely silent bugs).The correct function we should have used is
fieldcount
.The problem here is:
isbitstype
andisbits
that helps with this. Havingnfields(x)
andfieldcount(x)
give different answers is error prone.nfields(::DataType)
is just almost never what you want. These are internal fields so having some internal function for getting that count wouldn't be too bad.The text was updated successfully, but these errors were encountered: