Skip to content

Add enum variant constructors to bytecode VM #50

@synapticvoid

Description

@synapticvoid

Summary

Compile enum declarations into variant constructors and support qualified access (e.g. Color.Red).

Checklist

Compiler

  • Compile enum_declaration statement: for each variant, emit a struct_constructor callable with the qualified name (EnumName.VariantName)
  • Track known_enum_names so zero-field variants referencing an existing enum get nested coercion (single-field wrapper)
  • Compile qualified variant access (Color.Red) via field_access on a variable — resolve to the constructor in the environment

VM

  • Ensure variant instances are regular StructInstance values with kind = .case
  • Variant construction with fields reuses the struct construction path

Tests

  • Simple enum declaration + variant construction (zero fields)
  • Enum variant with fields (e.g. Shape.Circle(radius))
  • Qualified access Enum.Variant resolves correctly
  • Nested enum coercion (variant name matches an existing enum type)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions