Make `public` parse similar to `export`
I expect public to parse similarly to export, but that doesn't seem to be the case.
On Julia 1.11.0-rc3 (and all other versions I have tested):
julia> begin
export foo
end
julia> begin
public foo
end
ERROR: ParseError:
# Error @ REPL[2]:2:12
begin
public foo
# └─┘ ── Expected `end`
Stacktrace:
[1] top-level scope
@ none:1
julia> :(export foo)
:(export foo)
julia> :(public foo)
ERROR: ParseError:
# Error @ REPL[4]:1:10
:(public foo)
# └─┘ ── Expected `)`
Stacktrace:
[1] top-level scope
@ none:1
Is this a bug or mistaken expectations?
public very intentionally is only a valid keyword in toplevel (module) scopes to limit breakage of existing code. export always was a keyword (importantly, for Julia 1.x), so there's no need to be extra careful with existing code.
We may be able to improve the situation in Julia 1.13 or some-such following a deprecation. Depending on how important backwards compatibility vs consistent parsing of public/export is. Leaving this issue open to track that possibility.
Although the reasons here are plausible, this is surprising. See also this question.
Can we please document this properly? However, the documentation should probably be done in the official Julia documentation (I recognize, that here is the wrong place). Is there a dependency between the decision here and the documentation? As 1.11 will probably not change its behavior, it should be documented there in a point release anyway, shouldn't it?
The current wording
To mark a name as public without exporting it into the namespace of folks who call using NiceStuff, one can use public instead of export.
does not really mention that they are syntactically identical, but I read it like this and I think we can find a better wording where we mention that this restriction might be removed in future releases.
Sure, please make a pull request to JuliaLang/julia that documents this!
Done, thanks for considering it.