Skip to content

fix: translate a class with a field named _type - #63

Merged
ylluminate merged 1 commit into
vlang:masterfrom
ylluminate:fix-field-named-type
Nov 13, 2026
Merged

ylluminate merged 1 commit into
vlang:masterfrom
ylluminate:fix-field-named-type

Conversation

@ylluminate

@ylluminate ylluminate commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

A class with a field named _type made py2v fail on the whole file:

class Token:
    _type: str = "word"
Error parsing AST:
1:2661: Invalid json: Data: could not resolve sumtype `json2.Any` from "_type" field

The frontend wrote a class's field types and its field defaults as JSON objects keyed by the field name, and V's json2 reads a _type key in an object as a sum type tag when it decodes into json2.Any. Both are now written as lists of [name, value] pairs and read back that way, so a field name is never read as a key.

I ran into it on textual, in css/_style_properties.py.

Test plan

  • tests/cases/class_field_named_type.py with its expected V. Master fails on it with the error above; with this change the emitted V builds and prints word, as Python does.
  • v tests/run_tests.vsh: 179 passed, 0 failed (178 before, plus the new case), so every existing class case reads its fields and defaults the same through the new form.

@ylluminate
ylluminate merged commit 39b77ee into vlang:master Nov 13, 2026
2 checks passed
@ylluminate
ylluminate deleted the fix-field-named-type branch November 13, 2026 16:59
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