Skip to content

cgen: resolve generic map types in concrete contexts#27058

Open
guweigang wants to merge 1 commit into
vlang:masterfrom
guweigang:codex/generic-map-value-cgen
Open

cgen: resolve generic map types in concrete contexts#27058
guweigang wants to merge 1 commit into
vlang:masterfrom
guweigang:codex/generic-map-value-cgen

Conversation

@guweigang
Copy link
Copy Markdown
Contributor

@guweigang guweigang commented May 2, 2026

Summary

Fix C generation for generic map key/value types when a generic struct method is instantiated with multiple concrete types.

The bug showed up when a generic struct owns a map whose value type depends on T, for example map[string]StoredValue[T]. The C backend could reuse stale map key/value types from a previous concrete instantiation, producing mixed C types for different Ts.

Changes

  • Resolve map key/value types from the current concrete map type before generating map literals and map index access.
  • Reuse the same map type resolution path for map index expressions.
  • Resolve if value := map[key] guard variables from the concrete map value type.
  • Use the expected struct field map type when generating map literals inside struct initialization.
  • Add a regression test covering:
    • map[string]Wrapped[T]
    • map[string]T
    • map[int]Wrapped[T]
    • map[int]T
    • empty and seeded map literals
    • map set/get and if-guard access

Validation

  • ./v test vlib/v/tests/generics
  • ./v test vlib/v/tests/options/option_map_struct_field_init_test.v
  • ./v test vlib/v/tests/concurrency/shared_elem_test.v
  • ./v vlib/v/generics/new_generics_regression_test.v
  • git diff --check

@guweigang guweigang marked this pull request as ready for review May 2, 2026 10:50
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f2a33280f

ℹ️ 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".

Comment thread vlib/v/gen/c/struct.v Outdated
@guweigang
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f2a33280f

ℹ️ 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".

Comment thread vlib/v/gen/c/index.v
@guweigang guweigang force-pushed the codex/generic-map-value-cgen branch 2 times, most recently from 5744b07 to 1ea6bc7 Compare May 2, 2026 13:43
@guweigang guweigang force-pushed the codex/generic-map-value-cgen branch from 1ea6bc7 to 7b7400c Compare May 5, 2026 06:04
@guweigang
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ 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".

@guweigang
Copy link
Copy Markdown
Contributor Author

Is there anything I can do for this PR?

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.

1 participant