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

docs: fix scope type of a struct to hard #56755

Merged
merged 2 commits into from
Dec 18, 2024

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

@inkydragon inkydragon added the merge me PR is reviewed. Merge when all tests are passing label Dec 18, 2024
@inkydragon inkydragon changed the title change struct scope to hard in documentation docs: fix scope type of a struct to hard Dec 18, 2024
@giordano giordano merged commit 522624c into JuliaLang:master Dec 18, 2024
9 checks passed
@giordano giordano added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 and removed merge me PR is reviewed. Merge when all tests are passing labels Dec 18, 2024
stevengj pushed a commit that referenced this pull request Jan 2, 2025
Is struct not a hard scope?

```jl
julia> b = 1
       struct Tester
           tester
           Tester(tester) = new(tester)
           b = 2
           Tester() = new(b)
       end
       b
1
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants