Repository navigation
transform: keep main types in imported generics reached via comptime fields - #29184
Merged
Merged
Conversation
…fields A main struct field read with `value.$(field.name)` inside an imported generic body was resolved by its bare name in the callee module. When that module had its own type with the same name (e.g. a private `Cell`), the generic argument rebound to it: comptime field lists came back empty, or the build failed with `cannot use []Cell as []mod.Cell`. Lock colliding main types to `main.X` when struct field types and specialized call parameter types are spelled for a non-main module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…generics A main alias like `type Cells = []Cell` read from a comptime field inside an imported generic was still spelled bare, so its target was resolved in the callee module and rebound to that module's own `Cell`. Lock such aliases to `main.` when their target or name would collide. Also trim the test fixture to what the cases need and cover map, option, fixed array and alias fields.
MARCROCK22
added a commit
to MARCROCK22/v
that referenced
this pull request
Oct 1, 2026
vlang#29184 (main types kept in imported generics reached through compile-time fields) merges without conflicts with the monomorphization of the experiment.
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.
Fixes generic arguments inferred from comptime field selectors (
value.$(field.name)) inside an imported module that declares a type with the same short name as the caller's main type.Reproduction
Expected
['id'], got[]: insideelement_fields,Ewaslib.Cell. Callinglib.element_fields([]Cell{})directly frommainworked. With one more generic level (the pattern used by ui2's VML schema/value conversion), the build fails instead withcannot use []Cell as []lib.Cell, or a C type mismatch (main__Cellvslib__Cell). Found in vlang/ui2 (see vlang/ui2#48), where a privateui2.GridCellbrokeexamples/grid.Cause
The transformer passes types as text and main types are spelled bare. Two paths re-parsed that text in the callee module, where
Cellresolves to the module's own type:lookup_struct_field_type_uncached(type_propagation.v): the field type of a main struct ([]Cell).call_param_type_names(fn.v): parameter types of an already specialized call, rendered with.name().Fix
Both paths now lock colliding main types to
main.Xwith the existinglock_colliding_main_generic_type_textwhen the current module is notmain/builtin(and, for fields, when the owner struct is a main struct).canonical_generic_specialization_argstill stripsmain., so specialization names are unchanged. Both parts are needed; either alone still fails.Tests
New
vlib/v/tests/comptime_field_generic_arg_main_type/: array and struct fields throughvalue.$(field.name), nested specializations (E{}/$zero(E), iteration), and matching direct calls. It fails before the fix and passes after.Run on macOS arm64 with
V_MACOS_V3_NO_FALLBACK=1(so failures are not retried with the fallback compiler):v test vlib/v/tests/comptime vlib/v/tests/generics vlib/v/tests/generic_calls vlib/v/tests/module_type_named_like_main_type vlib/v/tests/comptime_field_generic_arg_main_type vlib/v/transform: 544/544 passed.v test vlib/v/tests/*_test.v vlib/v/tests/structs vlib/v/tests/same_name_types_str_methods vlib/v/tests/selective_import_generic_global_28881 vlib/v/tests/generic_fn_ptr_arg_28884 vlib/v/tests/generic_type_alias_method_27465 vlib/v/tests/serialisation: 467 passed, 12 failed, 11 skipped. The same 12 fail without this change (orm_*_test.v,sql_statement_inside_fn_call_test.v,string_escape_opaque_backslash_test.v, runtime exit 11).v test .with the originalGridCellname: no new failures;examples/grid/grid_test.vpasses.v test-all.🤖 Generated with Claude Code