Repository navigation
lib: hide non-pub struct fields across libraries - #215
Merged
Merged
Conversation
A hidden struct can still flow through a pub function return value. Field access did not consult the struct type visibility, so h.x was readable and writable outside the owning library even though the type name and its methods were hidden. EXPR_FIELD now resolves the struct type symbol with find_gsym under the current library and reports N03 Undefined field when the type is not visible. Same library, pub structs and @core -> @std reads are unchanged. Tests extend the cross-library fixture with hidden/shown structs and pub factory functions: hidden field read/write -> N03, pub field read -> runs. Docs state that fields currently follow the struct type visibility; per-field pub is still an open language decision. selfhost/bootstrap/check green; canary 5/5 unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
非
pub结构体的类型名和方法已经跨库隐藏,但字段没有:h.x = 5同样可写。原因:EXPR_FIELD解析到 struct 后直接返回字段类型,没有检查结构体类型符号的可见性。修法
EXPR_FIELD在命名 struct 分支用find_gsym(struct_ni)取当前库可见的类型符号;不可见时报 N03 Undefined field 并返回错误类型。g_cur_lib < 0的声明期解析;同库访问、pubstruct、@core -> @std均不变。infer_expr(target),所以读和写一起收口。判据
test_pub_visibility的跨库 fixture 增加:HiddenBox+pub fn makeHiddenBox() -> HiddenBox:h.x读 → N03,h.x = 5写 → N03;ShownBox, pub+pub fn makeShownBox() -> ShownBox:s.y可读,运行返回预期值。边界
pub类型整体不可见,字段随之不可见。pub类型的字段当前整体公开;逐字段pub标签尚未实现,这是需要裁决的语言设计项(默认公开 vs 默认私有 + 逐字段导出)。文档已按现状写明。selfhost-tests/bootstrap-tests/check全绿;canary5/5 不变。