You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
D100: fields are private to their package unless pub #2209
D100 (spec v7.27 §18.3): "The rule is the same for functions, methods, types, fields, constants, and globals." Eric: "Vec's buffer and length should be private to the std package, invisible to users, and freely usable across std's own files."
Today a field has no visibility at all: type P { pub x: i32 } does not parse ("expected identifier"), and every field of every pub type is readable and constructible from any package (Vec { ptr: …, len: …, cap: …, elem_size: … }).
Needed:
Parser: pub before a field name, in both type-body forms (Parser.w parse_struct_body, parse_struct_body_block), carried in the AST so copies and the renderer keep it.
Sema: a field read, a struct literal naming the field, and a pattern binding it, from another package, refused when the field is not pub (same message family as other privacy errors).
std: mark pub the fields that are API (measured: every field user code in test/, examples/, uat/ reads); Vec's ptr/len/cap/elem_size and similar representation fields stay private.
Tests: a cross-package field read and literal refused; same-package access allowed.
Activity
D100: a field without pub is private to its package (withlang-dev#2209)…