Skip to content

Variables and Fields Starting with Underscore #282

@yaskhan

Description

@yaskhan

Python often uses underscores prefixing fields and variables to indicate they are private or internal (e.g., _first, _last, _match_subject_1). However, the V compiler enforces strict naming rules where struct field names and variable names cannot start with an underscore (_). The transpiler preserves these underscores, causing compilation errors.

Expected Behavior:
The transpiler should map Python's private naming convention (_field) to a valid V naming convention (e.g., stripping the leading underscore, potentially using V's module-level visibility rules to mark them as non-pub).

Output from V compiler:

test_even_more_features.v:6:5: error: field name `_first` cannot start with `_`
    4 | }
    5 | pub struct User {
    6 |     _first string
      |     ~~~~~~~~~~~~~

test_even_more_features.v:40:5: error: variable name `_match_subject_1` cannot start with `_`
   38 | pub fn match_status(status SumType_IntString) {
   39 |     // Match statement converted to separate if blocks
   40 |     _match_subject_1 := status
      |     ~~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjules

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions