Skip to content

v3: parse pointer-bearing generic args like Foo[fn (&T) int] as type args - #28938

Open
medvednikov wants to merge 1 commit into
masterfrom
fix/28884-generic-method-global-fn-ptr-alias
Open

medvednikov wants to merge 1 commit into
masterfrom
fix/28884-generic-method-global-fn-ptr-alias

Conversation

@medvednikov

Copy link
Copy Markdown
Member

Summary

is_fixed_array_len_text decides whether the text inside Base[...] is a fixed-array length or a generic type argument. It treated any & after the first character as a bitwise-and length operator. So foo.Foo[fn (&Baz) int] was read as a fixed array of foo.Foo with length fn (&Baz) int, and field access failed with error: `[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 for Foo[[]&T], Foo[map[K]&T], Foo[?&T], Foo[&&T], Foo[Box[&T]], Foo[chan &T] and Foo[fn () &T].

The checker now:

  • never treats argument text that starts with type-only syntax (&, ?, !, [, ..., map[, fn, chan, thread, shared, atomic, mut) as a length;
  • ignores &/- nested inside brackets.

The transform and cgen typeof helpers share the same heuristic. They get the same &/?/! prefix check, so ?&T and &&T instances 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's set method.

Fixes #28884

Validation

  • New vlib/v/tests/generic_fn_ptr_arg_28884/ covers:

    • the alias and inline fn-type globals;
    • locals, a struct field and a mut param;
    • named-param and pointer-returning fn types;
    • the nested pointer forms above.

    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.v hangs, 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 __global tests in vlib/v/tests: 42/42 passed

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T12:41:40.824690Z cbd9c57 PR opened
ℹ️ 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" or "@codex security review".

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v3: Generic method on a global container of function pointers calls a missing specialization

1 participant