v3: parse pointer-bearing generic args like Foo[fn (&T) int] as type args - #28938
Open
medvednikov wants to merge 1 commit into
Open
medvednikov wants to merge 1 commit into
medvednikov wants to merge 1 commit into
Conversation
…gths (fix #28884) `is_fixed_array_len_text` treated every non-leading `&` as a bitwise-and length operator, so `Foo[fn (&Baz) int]` (and `Foo[[]&T]`, `Foo[?&T]`, `Foo[&&T]`, `Foo[Box[&T]]`, ...) was parsed as a fixed array of `Foo` with length `fn (&Baz) int`. Field access then failed with "`[fn (&Baz) int]foo.Foo` has no property `value`", and fn-field calls became "unknown function". Reject argument text that starts with type-only syntax (`&`, `?`, `!`, `[`, `...`, `map[`, `fn`, `chan`, `thread`, `shared`, `atomic`, `mut`) and ignore `&`/`-` nested in brackets. The transform and cgen typeof helpers get the same `&`/`?`/`!` prefix check so `?&T` and `&&T` instances are not mangled as fixed arrays later on.
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. |
This branch has not been deployed
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
is_fixed_array_len_textdecides whether the text insideBase[...]is a fixed-array length or a generic type argument. It treated any&after the first character as a bitwise-and length operator. Sofoo.Foo[fn (&Baz) int]was read as a fixed array offoo.Foowith lengthfn (&Baz) int, and field access failed witherror: `[fn (&Baz) int]foo.Foo` has no property `value`. Fn-field calls through it became unknown functions. This happened in every context (globals, locals, struct fields, params), and also forFoo[[]&T],Foo[map[K]&T],Foo[?&T],Foo[&&T],Foo[Box[&T]],Foo[chan &T]andFoo[fn () &T].The checker now:
&,?,!,[,...,map[,fn,chan,thread,shared,atomic,mut) as a length;&/-nested inside brackets.The transform and cgen typeof helpers share the same heuristic. They get the same
&/?/!prefix check, so?&Tand&&Tinstances are not mangled as fixed arrays later on.The alias form from the report (
type Bar = fn (&Baz) int,__global global_value foo.Foo[Bar]) already compiles and runs correctly on current master.foo__Foo_fn_ptr_Baz_int__set, the function the report says is missing, is the name V3 gives the inline instance'ssetmethod.Fixes #28884
Validation
New
vlib/v/tests/generic_fn_ptr_arg_28884/covers:mutparam;It stores real fns and calls them through the containers. 1/1 passed; it fails on master.
./v -silent vlib/v/compiler_errors_test.v: 1720 passed, 1 failed (modules/anon_struct_private_field_err, same failure on master)./v -silent test vlib/v/gen/c/: 27/27 passed./v -silent test vlib/v/tests/generics/: 321/321 passed./v -silent test vlib/v/transform/: 17/17 passed./v -silent test vlib/v/types/: 30 passed;checker_ownership_alias_test.vhangs, as it does on master (V3: checker_ownership_alias_test.v never finishes compiling (-d ownership compiler spins at 100% CPU) #28923)typeof, fixed-array and
__globaltests invlib/v/tests: 42/42 passed