Skip to content

fix(typecheck): check enum variant constructor arguments against their payload - #148

Merged
omdxp merged 1 commit into
mainfrom
fix/enum-payload-typecheck
Sep 19, 2026
Merged

omdxp merged 1 commit into
mainfrom
fix/enum-payload-typecheck

Conversation

@omdxp

@omdxp omdxp commented Sep 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • ret .Circle("x"), ret Shape.Circle("x"), ret .Rect(1) (too few) and ret Shape.Circle(1, 2) (too many) were all accepted by typecheck. The checker only validated a shorthand's variant name and any nested shorthand, never the constructor's argument count or types.
  • A shared check (check_variant_args) now holds a constructor's count and each argument's type to the declared payload, for both the shorthand and the qualified form. A generic enum's parameters, defaults included, are replaced by what the expected type instantiated them as: .Err(1) where a Res<num> is expected reports argument 1 of variant 'Err' of 'Res' expects str, found num. A parameter the expected type does not resolve stands for anything, and a nested shorthand is held to its slot's own enum.
  • A standalone qualified constructor (Shape s = Shape.Circle("x")) is checked with no expected type.
  • It builds on the per-variant payload types the checker already recorded for nested shorthand checking. The error shows in the editor through the existing diagnostics path.

Test plan

  • 3-stage self-compile bootstrap clean: the compiler and stdlib, which build enum values everywhere, type-check under the new rule with no false positives
  • fun test . 33/33 files, fun -fmt-check-all clean, fun lint src clean
  • scripts/run_examples.sh 218/218 (known pre-existing let_and_lowlevel_types.fn flake)
  • New typecheck tests for a wrong type, too few, too many and no arguments (shorthand and qualified), default-filled generic expectations, a qualified constructor against its expected enum, a standalone qualified constructor, a nested shorthand, and an accepting case covering every valid form; plus an fls diagnostic test

…r payload

.Circle("x") and Shape.Circle("x") into a num payload, or a wrong number of arguments, were accepted and only surfaced (if at all) as a C compile error. A shared check now holds a constructor's argument count and each argument's type to the declared payload, in both the shorthand and the qualified form, with a generic enum's parameters (defaults included) replaced by what the expected type instantiated them as. A nested shorthand in an argument is held to that slot's own enum.
@omdxp
omdxp merged commit e406c1e into main Sep 19, 2026
4 checks passed
@omdxp
omdxp deleted the fix/enum-payload-typecheck branch September 19, 2026 23:14
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