Skip to content

Define @__FUNCTION__ as an alias to var"#self#" #58909

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 9 commits into
base: master
Choose a base branch
from

Conversation

MilesCranmer
Copy link
Member

@MilesCranmer MilesCranmer commented Jul 5, 2025

Just as @__MODULE__ refers to the enclosing module object, the internal variable var"#self#" can be used to refer to the enclosing function object.

This PR creates an alias @__FUNCTION__ for this variable to match the naming conventions of existing reflection macros (@__MODULE__, @__FILE__, etc.).

Fixes #58908 Fixes #6733

@nsajko nsajko added feature Indicates new feature / enhancement requests macros @macros labels Jul 5, 2025
@KristofferC
Copy link
Member

KristofferC commented Jul 5, 2025

Referencing the discussion about implementations of this in #6733.

@giordano
Copy link
Member

giordano commented Jul 5, 2025

This should also be added to the docs. I'm surprised this isn't caught by CI.

@giordano giordano added the needs news A NEWS entry is required for this change label Jul 5, 2025
@MilesCranmer
Copy link
Member Author

Thanks; done

@nsajko nsajko removed the needs news A NEWS entry is required for this change label Jul 6, 2025
_function_macro_error() = (@noinline; error("@__FUNCTION__ can only be used within a function"))

"""
@__FUNCTION__ -> Function
Copy link
Contributor

Choose a reason for hiding this comment

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

See https://docs.julialang.org/en/v1.13-dev/manual/documentation/#man-writing-documentation

When included, a return type should be written after the signature, separated by ::, while a named return value should be separated by ->, with a space on both sides.

Also see PR #57012, PR #57583.

I think simply doing it like this might be the best:

Suggested change
@__FUNCTION__ -> Function
@__FUNCTION__

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied the style from the @__MODULE__ one.

If we change it, should @__MODULE__ also be updated to remove the -> Module?

Copy link
Member Author

@MilesCranmer MilesCranmer Jul 6, 2025

Choose a reason for hiding this comment

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

It looks like it's the same for @__LINE__ -> Int, @__FILE__ -> String, and @__DIR__ -> String.

Seeing those, I'm inclined to keep it as-is. Ok to resolve?

Copy link
Contributor

Choose a reason for hiding this comment

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

Surely the @__MODULE__, @__LINE__, @__FILE__ and @__DIR__ were simply not yet updated for the new style.

Seeing those, I'm inclined to keep it as-is. Ok to resolve?

No? IMO if you don't agree with the style guide, you should make a separate PR to change the style guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests macros @macros
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Marking var"#self#" as stable? add builtin @__FUNCTION__ macros
6 participants