transform: avoid field-name collisions for bound methods - #28787
medvednikov wants to merge 4 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cfd8f7f0fc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // A selector on a known struct may be a bound method. Do not infer its | ||
| // type from a same-named field on an unrelated struct; let the checker | ||
| // supply the method's function type instead. | ||
| return '' |
There was a problem hiding this comment.
Preserve type resolution through nested embeddings
When a field is promoted through two or more embedded structs, this return incorrectly classifies it as a possible method and produces no type. embedded_field_for_promoted_field in vlib/v/transform/struct.v checks only whether the immediate embedded struct directly declares the field, so a valid selector such as Baz.x in vlib/v/tests/structs/nested_struct_embed_selector_test.v (Baz -> Bar -> Foo.x) reaches this branch; before this change, the unique-field fallback returned int. Direct callers of resolve_selector_type, including specialized array/loop inference paths, can consequently lose the field type when a checker annotation is unavailable, so the known-struct early return should occur only after a recursive promoted-field lookup.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in ff12b02.
Replaced the one-level promoted-field lookup with the existing recursive struct_field_path_for_field helper, then resolve the field type from the final owning struct. Pointer embeddings are unwrapped for the owner lookup, and the known-struct guard still prevents borrowing an unrelated same-named field's type.
Added a checker-free regression covering eight combinations of value/pointer receivers, value/pointer embeddings, and scalar/array fields, plus nearer-field and receiver-field shadowing. The original method/field collision regression remains in place.
Verified that the committed diff matches the prepared two-file patch. V compilation, formatting, and runtime tests remain unrun locally: the sandbox has no V compiler, and bootstrap downloads fail DNS resolution. Leaving the thread open for re-review.
Use the recursive embedding path before rejecting unrelated field-name fallbacks for known receivers. Cover nested value/pointer embeddings, scalar/array fields, and nearer-field shadowing without checker annotations. Addresses the nested-embedding review on #28787.
Fixes #28784.
Summary
fn ()callback assignment, a callback that reads receiver state, reassignment to a different receiver, invocation after assignment, and resetting the callback tonone.Diagnosis
In the report,
Modelhas anon_donemethod but noon_donefield.resolve_selector_type_uncachednevertheless falls through tolookup_unique_field_type('on_done'), which can supply the?fn ()field type fromProcess. A method value must not acquire the optionality of an unrelated field merely because their names match.After receiver-specific field and promoted-field lookup fails for a known struct, leave field inference unresolved so the existing checker-backed expression-type fallback can supply the method's function type. The compiler change is four added lines, including its explanatory comment.
Validation status
Draft: the diagnosis and patch have been reviewed statically, but reproduction and runtime validation are not yet complete.
9bfa1dc3f3455d5733d5c226662b6aaba8544f2c: only the four-line compiler change and the two new regression files are present.Could not resolve host: github.com/raw.githubusercontent.com). Repository reads and branch commits were made through the connected GitHub API.Commands still requiring an environment with V available:
The focused regressions should also be checked against the parent revision to establish a failing-before/passing-after result before marking this ready for review.