julia icon indicating copy to clipboard operation
julia copied to clipboard

Cannot quote `public` statements

Open mbauman opened this issue 2 years ago • 5 comments

It'd be great if this could work:

julia> :(public foo)
ERROR: ParseError:
# Error @ REPL[13]:1:10
:(public foo)
#        └─┘ ── Expected `)`
Stacktrace:
 [1] top-level scope
   @ none:1

Found because I was exploring public behaviors interactively and was trying to do something like the below — the equivalent using export works:

julia> @eval Base begin
       foo = 1
       public foo
ERROR: ParseError:
# Error @ REPL[16]:3:8
foo = 1
public foo
#      └─┘ ── Expected `end`
Stacktrace:
 [1] top-level scope
   @ none:1

mbauman avatar Sep 25 '23 19:09 mbauman

Oh, yeah, public exprs print like this should work:

julia> Expr(:public, :foo)
:(public foo)

julia> @eval Base begin
       foo = 1
       $(Expr(:public, :foo))
       end

julia> Base.ispublic(Base, :foo)
true

mbauman avatar Sep 25 '23 19:09 mbauman

What about adding this issue to the 1.11 milestone? I think it would be strange if 1.11.0 introduced the public construction, but didn't allow it when quoting. If this is added later, then you cannot use it in packages that are also supposed to work with 1.11.0.

matthias314 avatar Apr 08 '24 13:04 matthias314

FWIW, this was done intentionally. pubilc is only a keyword at toplevel to reduce breakage (b.c. it isn't a keyword in 1.10). We can probably expand that to toplevel + quotes, though.

LilithHafner avatar Apr 22 '24 16:04 LilithHafner

Is there any progress here? Othewise, this doesn't seem really important enough to be on the milestone.

KristofferC avatar May 14 '24 15:05 KristofferC

It would be easier to change this parsing behavior after this minor refactoring which I'm waiting for review on.

LilithHafner avatar May 14 '24 15:05 LilithHafner

Is that why this string fails to parse?

julia> Meta.parse("@static if true public foo end")
ERROR: ParseError:
# Error @ none:1:24
@static if true public foo end
#                      └─┘ ── Expected `end`
Stacktrace:
 [1] #parse#3
   @ ./meta.jl:242 [inlined]
 [2] parse
   @ ./meta.jl:234 [inlined]
 [3] parse(str::String; filename::String, raise::Bool, depwarn::Bool)
   @ Base.Meta ./meta.jl:276
 [4] parse(str::String)
   @ Base.Meta ./meta.jl:274
 [5] top-level scope
   @ REPL[32]:1

Noticed it when I tried to use that expression in a package and it failed to load.

JamesWrigley avatar Sep 04 '24 15:09 JamesWrigley

It's related, but no. public is not quoted in that example. Also, FYI, using @static will not help with constructs that parse in only some versions. Contrary to it's docstring in Julia 1.11 and earlier, @static partially evaluates at macro expansion time, not parse time. The whole expression is parsed before @static takes effect. The docstring was fixed in https://github.com/JuliaLang/julia/pull/54206

LilithHafner avatar Sep 06 '24 20:09 LilithHafner