Skip to content

Export fieldindex #58119

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PatrickHaecker
Copy link
Contributor

At present, we export Base.fieldname, which maps a field's index to its symbol. Although we have the inverse function, Base.fieldindex, which maps a field's symbol to its index, defined and documented, we currently do not export it.

This PR changes this and exports it to enhance the consistency and completeness of the field introspection functions. Additionally, it is unlikely that the function will undergo fundamental changes in the future, so exporting it should not pose a significant maintenance burden. The interface is likely fully defined by the following two properties.

@test fieldname(Some{Int}, Base.fieldindex(Some{Int}, :value)) === :value
@test Base.fieldindex(Some{Int}, fieldname(Some{Int}, 1)) === 1

Besides doing the export, this PR adapts the documentation and adds test cases.

Fixes #58092

Thanks to @nsajko for the support in covering all artifacts.

At present, we export `Base.fieldname`, which maps a field's index to
its symbol. Although we have the inverse function, `Base.fieldindex`,
which maps a field's symbol to its index, defined and documented, we
currently do not export it.

This PR changes this and exports it to enhance the consistency and
completeness of the field introspection functions. Additionally, it is
unlikely that the function will undergo fundamental changes in the
future, so exporting it should not pose a significant maintenance
burden. The interface is likely fully defined by the following two
properties.

```julia
@test fieldname(Some{Int}, Base.fieldindex(Some{Int}, :value)) === :value
@test Base.fieldindex(Some{Int}, fieldname(Some{Int}, 1)) === 1
```

Besides doing the `export`, this PR adapts the documentation and adds
test cases.

Fixes JuliaLang#58092

Thanks to @nsajko for the support in covering all artifacts.
Copy link
Member

@ararslan ararslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I've wondered before why this wasn't exported but similar functions were. Could be worth an addition to NEWS.md too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fieldindex should probably be exported
2 participants