Skip to content

Make invalid Display states unrepresentable in the type system #56

@garritfra

Description

@garritfra

Several Display impls currently panic at runtime when given invalid type combinations:

  • Instr::Cmp panics on Type::Aggregate (aggregate types can't be compared)
  • Instr::Store panics on Type::Aggregate
  • Instr::Load panics on Type::Byte/Type::Halfword (ambiguous sub-word load) and Type::Aggregate
  • Statement::Assign panics on non-Value::Temporary targets

These are programmer errors caught at format-time, but ideally the type system would prevent constructing these invalid states in the first place. For example:

  • Statement::Assign could take a String (temporary name) instead of Value, since only Temporary is valid
  • Instr::Cmp / Instr::Load / Instr::Store could use a restricted type enum that excludes Aggregate (and for Load, also Byte/Halfword)

This would shift these checks from runtime panics to compile-time errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions