Jule `pub` visibility: unintended public exposure of struct fields across package boundaries
0 reputation · 22 Aug 2022, 09:17 UTC
0 reputation · 22 Aug 2022, 09:17 UTC
I want to keep a Jule package's internal types and functions inaccessible to importing packages, exposing only a minimal API surface. My concern is accidental public access: a declaration that I intended to be package-private ending up callable from outside the package.
Jule documents visibility through an explicit access modifier (the pub keyword) rather than case-based rules, so the default visibility of a plain declaration is the deciding factor. The unresolved point is exactly how the compiler treats mixed declarations — for example, a non-public struct whose individual fields are marked pub, or a public function returning a non-public type — and whether any of these combinations silently widen access beyond what the author intended.
Because the supplied research material concerns Java's SecurityManager rather than Jule's visibility model, I am treating the exact modifier semantics as unverified and plan to confirm them against the current Jule manual and a small two-package test program before relying on them.
pub on a field of a non-public struct have any effect for external importers?pub inside a non‑public struct does not make that field visible outside its package.pub declarations that are never referenced from other packages.Based on the current Jule documentation and typical language design:
pub modifier only affects the visibility of the entity it annotates; it does not lift the visibility of enclosing types.pub.These rules keep the surface area small: a type must be explicitly made public before any of its members can be seen, and a function cannot leak hidden types through its signature because callers lack the ability to name them.
pkg with struct S { pub x: i32 } (no pub on struct) and a public function fn get() -> S { S { x: 1 } }.pkg.main, import pkg::get and try to access the returned value’s x field or name type S; the call succeeds but field access and type name are rejected.pub struct S { pub x: i32 } and recompile; now main can name S and read x.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.