JuliaSyntax.jl icon indicating copy to clipboard operation
JuliaSyntax.jl copied to clipboard

Make `public` parse similar to `export`

Open GunnarFarneback opened this issue 1 year ago • 5 comments

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?

GunnarFarneback avatar Sep 05 '24 15:09 GunnarFarneback

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.

pfitzseb avatar Sep 05 '24 15:09 pfitzseb

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.

LilithHafner avatar Sep 06 '24 20:09 LilithHafner

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.

PatrickHaecker avatar Mar 27 '25 14:03 PatrickHaecker

Sure, please make a pull request to JuliaLang/julia that documents this!

LilithHafner avatar Mar 27 '25 15:03 LilithHafner

Done, thanks for considering it.

PatrickHaecker avatar Mar 28 '25 12:03 PatrickHaecker