Skip to content

throw an error instead of falling back to getfield for Ptr types #542

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

ghyatzo
Copy link

@ghyatzo ghyatzo commented Apr 8, 2025

Hello,

The generated Base.getproperty(x::Ptr{T}, f::Symbol) emits a getfield(x,f) if all other cases are exhausted.
But getfield is not really defined for Ptr (which makes sense, since it doesn't have any field) and static analysis tools like JET generate a lot of noise about it.

What about throwing an exception instead? It shouldn't be breaking since we'd be throwing an exception anyway, and provides a better error message and makes analysis tools happy.

@Gnimuc
Copy link
Member

Gnimuc commented Apr 9, 2025

This fallback pattern is used ubiquitously in Julia Base.

@ghyatzo
Copy link
Author

ghyatzo commented Apr 9, 2025

Yes, It's a common pattern. And I think it makes absolute sense when overloading the getproperty of objects that do have fields.

But when used to give an isbits type virtual fields I think that same pattern is a bit misplaced.

Anyway, this is minor, it would just be to play nicer with static analyzers. I'll leave this here if you change your mind!

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.

2 participants