Skip to content

fix(typechecker): validate typed expressions and enum constructors #152

@graydeon

Description

@graydeon

Summary

The host type checker still has two live correctness gaps in expression checking:

  • typed expressions return the annotated type without verifying that the value matches it
  • constructor expressions still have TODO-level handling for enum variant lookup and field ordering

These paths sit in active checking logic, so they can permit incorrect programs or reject valid ones depending on the input shape.

Why this matters

  • incorrect acceptance/rejection at the typechecker layer undermines compiler trust
  • these gaps affect core expression semantics, not optional tooling
  • both issues are small enough to batch into one focused fix

Current behavior

Examples from the current implementation indicate:

  • TypedExpr returns the annotation after checking the value, but does not enforce compatibility
  • constructor checking still treats named-field construction as a tuple-shaped placeholder instead of validating the target variant and field order

Expected behavior

  • typed expressions should validate that the value conforms to the annotated type
  • enum constructor expressions should resolve the target variant and validate field names/order/payload shape correctly

Suggested scope

  • add regression tests for invalid typed expressions and enum constructor mismatches
  • implement type compatibility checks for TypedExpr
  • implement proper enum variant lookup and constructor field validation

Acceptance criteria

  • invalid typed expressions fail with clear diagnostics
  • invalid enum constructor field shapes fail with clear diagnostics
  • valid typed expressions and valid enum constructors continue to pass
  • targeted regression tests cover both code paths

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions