Skip to content

Commit 77f264f

Browse files
Documentation: public needs global scope (JuliaLang#57916)
1 parent 3e063f6 commit 77f264f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

doc/src/devdocs/ast.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,18 @@ parses as `(macrocall (|.| Core '@doc) (line) "some docs" (= (call f x) (block x
119119
| `import Base: x` | `(import (: (. Base) (. x)))` |
120120
| `import Base: x, y` | `(import (: (. Base) (. x) (. y)))` |
121121
| `export a, b` | `(export a b)` |
122+
| `public a, b` | `(public a b)` |
122123

123124
`using` has the same representation as `import`, but with expression head `:using`
124125
instead of `:import`.
125126

127+
To programmatically create a `public` statement, you can use `Expr(:public, :a, :b)` or,
128+
closer to regular code, `Meta.parse("public a, b")`. This approach is necessary due to
129+
[current limitations on `public`](@ref Export-lists). The `public` keyword is only
130+
recognized at the syntactic top level within a file (`parse_stmts`) or module. This
131+
restriction was implemented to prevent breaking existing code that used `public` as an
132+
identifier when it was introduced in Julia 1.11.
133+
126134
### Numbers
127135

128136
Julia supports more number types than many scheme implementations, so not all numbers are represented

doc/src/manual/modules.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ and above. To maintain compatibility with Julia 1.10 and below, use the `@compat
114114
VERSION >= v"1.11.0-DEV.469" && eval(Meta.parse("public a, b, c"))
115115
```
116116

117+
`export` is a keyword wherever it occurs whereas the `public` keyword is currently limited to the
118+
syntactic top level within a file or module. This limitation exists for compatibility reasons,
119+
as `public` was introduced as a new keyword in Julia 1.11 while `export` has existed since Julia
120+
1.0. However, this restriction on `public` may be lifted in future releases, so do not use `public`
121+
as an identifier.
122+
117123
### Standalone `using` and `import`
118124

119125
For interactive use, the most common way of loading a module is `using ModuleName`. This [loads](@ref

0 commit comments

Comments
 (0)