Skip to content
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

change struct scope to hard in documentation #56755

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

Conversation

ArnoStrouwen
Copy link
Contributor

Is struct not a hard scope?

julia> b = 1
       struct Tester
           tester
           Tester(tester) = new(tester)
           b = 2
           Tester() = new(b)
       end
       b
1

@inkydragon inkydragon added the docs This change adds or pertains to documentation label Dec 5, 2024
Copy link
Member

@LilithHafner LilithHafner left a comment

Choose a reason for hiding this comment

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

Good catch. struct does indeed appear to be a hard scope based on this result and also how it lowers.

It is worth noting that assignments within structs are not well supported

julia> struct Tester
           b = 2
           Tester() = new(b)
       end
ERROR: syntax: "b = 2" inside type definition is reserved around REPL[1]:1
Stacktrace:
 [1] top-level scope
   @ REPL[1]:1

@ArnoStrouwen
Copy link
Contributor Author

It is worth noting that assignments within structs are not well supported

This is going off-topic, but the docs would benefit from more clearly defining this.
For example, why is the following allowed, but your example not.

struct Tester
    begin end
    b = 2
    Tester() = new(b)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants