Skip to content

cgen: skip _v_type_idx_ emission for invalid-C-identifier cnames (fix v build-module vlib/orm) - #27891

Open
eptx wants to merge 1 commit into
vlang:masterfrom
eptx:fix/typeidx-invalid-cname
Open

cgen: skip _v_type_idx_ emission for invalid-C-identifier cnames (fix v build-module vlib/orm)#27891
eptx wants to merge 1 commit into
vlang:masterfrom
eptx:fix/typeidx-invalid-cname

Conversation

@eptx

@eptx eptx commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

v build-module vlib/orm (and build-module of any module importing orm) fails with a C compilation error on current master:

cc: error: expected ';' after top level declarator
u32 _v_type_idx_orm__[]orm__Primitive___orm__[]bool___orm__[]f32___...(); // 1build module vlib/orm

Anonymous sum-type symbols (orm's []Primitive | []bool | … family) carry a cname containing literal [] — not a valid C identifier — and the build-module / -usecache type-idx emission writes it verbatim into the helper declaration.

Fix

Skip _v_type_idx_ emission for cnames containing [, in both emission loops. Such a cname can never be referenced through _v_type_idx_<cname>() either (the call site would be equally invalid C), so the skip loses nothing.

Verification

  • Before: ./v build-module vlib/orm → the C error above. After: builds clean.
  • ./v test vlib/orm → 38/38 passed.
  • (The separate -usecache duplicate-symbols link failure on hello_world reproduces identically on unpatched master — pre-existing and unrelated to this change.)

Anonymous sum-type symbols (e.g. orm's `[]Primitive | []bool | ...`)
carry a cname containing literal `[]`, which is not a valid C
identifier. The build-module / -usecache type-idx emission wrote it
verbatim:

    u32 _v_type_idx_orm__[]orm__Primitive___orm__[]bool___...();

producing uncompilable C, so `v build-module vlib/orm` (and any module
importing orm) failed with 'expected ; after top level declarator'.

Such a cname can never be *referenced* through `_v_type_idx_<cname>()`
either — the call site would be equally invalid C — so skipping the
emission for cnames containing `[` loses nothing. Both emission loops
(the build-module path and the -usecache path) get the same guard.

Repro before this change: `v build-module vlib/orm`. After: builds
clean; `v test vlib/orm` 38/38.
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