Skip to content

feat: auto-derive Hashable for payload-free enums#146

Merged
frendsick merged 1 commit intomainfrom
feat/derive-enum-hashable
Apr 26, 2026
Merged

feat: auto-derive Hashable for payload-free enums#146
frendsick merged 1 commit intomainfrom
feat/derive-enum-hashable

Conversation

@frendsick
Copy link
Copy Markdown
Owner

Summary

  • Closes Derive enum hash/eq from int discriminant by default #141. Payload-free enums now satisfy Hashable automatically — no manual impl block needed.
  • Color::hash is the discriminant cast to int (always non-negative). Color::eq is ==. Synth runs once after resolve_identifiers_global, before type-checking.
  • Silent override: if the user defines {Name}::hash or {Name}::eq, the synthesized version is suppressed and the manual one wins.
  • Drops 5 manual impl <Kind> blocks in compiler/common.casa (TokenKind, IntrinsicKind, KeywordKind, DelimiterKind, OperatorKind) — synth now provides them.
  • Out of scope: terminal builtin types (int, bool, char, ptr, str, cstr) — tracked in Auto-derive Hashable for terminal builtin types #145.

Test plan

  • tests/test_compiler.sh — 25/25 (incl. self_compilation + fixed_point)
  • tests/test_examples.sh — 40/40 (incl. new examples/enum_hashable_derive.casa)
  • tests/test_formatter.sh — 64/64
  • New unit tests in tests/compiler/test_enum.casa cover: hash/eq are synthesized for payload-free enums, signatures are correct, payload-bearing enums are skipped, manual impl overrides synth.
  • All .casa files run through ./casafmt.

Synthesize {Name}::hash and {Name}::eq for enums whose variants carry
no inner values, so they satisfy the Hashable trait without manual
impl blocks. Synth runs once per compile after resolve_identifiers_global,
skips any name the user already defined (silent override), and produces
inline bodies (cast-to-int for hash, == for eq) that need no std import.

Removes 5 manual impl blocks in compiler/common.casa now provided by
the synth.
@frendsick frendsick merged commit 0548fdf into main Apr 26, 2026
2 checks passed
@frendsick frendsick deleted the feat/derive-enum-hashable branch April 26, 2026 16:24
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.

Derive enum hash/eq from int discriminant by default

1 participant