Repository navigation
fix(hy-check): reject field selectors on pointers to non-struct and multi-pointer types (#4403) - #4448
Open
SuperPiIot wants to merge 1 commit into
Conversation
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.
Summary
Fixes #4403
In
check_field_selector_kind(compiler/crates/hy-check/src/buildable.rs), everyOpKind::Pointer(_)was previously treated as struct-like. Becausestruct_base_namereturnsNonefor non-struct pointers (*int,*string,*[]T,*map[K]V,*bool,*chan T) and recursively unwraps multi-level pointers (**T), selectors through those types hadis_struct_like == true && struct_known == falseand returned early without emittingHYB-E1002. As a result,hyb checkaccepted invalid selectors that failgo buildwithundefined (type ... has no field or method ...).This PR restricts
is_struct_likeincheck_field_selector_kindto directOpKind::Struct(_)and single-levelOpKind::Pointer(OpKind::Struct(_)), so selectors on pointers to non-structs and multi-level pointers (**int,**S) fail closed withHYB-E1002on both reads and stores, while preserving field/method access on*Sand generic*box[T].Verification
compiler/crates/hy-check/tests/pointer_to_non_struct_field_selector.rscovering reads and stores on*int,*string,*[]int,*map[string]int,*bool,*chan int,**int,**pt,*pt, and*box[int].cargo test --manifest-path compiler/Cargo.toml -p hy-check --lib --test pointer_to_non_struct_field_selector --test emit_build_guards --test member_defer_and_append_guards: 234 passed, 0 failed (184 lib + 31emit_build_guards+ 9member_defer_and_append_guards+ 10 new tests).Payout Wallet
0xf084cF0076F91AA48C2370F427C399dAA8C1f07F