type checker, phase 2: return hints checked

- parse the `-> T` return hint into the function context (was consumed
  and dropped).
- `return <literal>` is checked against the declared return type: a
  concrete mismatch raises at compile time.  Opaque/unknown returns and
  non-literal expressions stay permissive.
- tests/types.cat + suite: a valid `-> int` function.  Suite 140 -> 141.
This commit is contained in:
Minus committed 2026-11-18 17:15:42 +00:00
1 parent 48b1b84ea6
commit 96e8f516cc
3 files changed
+19 -4

No files matched your search

+1
View File
@@ -258,6 +258,7 @@ out=`$BIN tests/types.cat`
check "types-ok" "ok: 42 3.5 hi true" "`echo "$out" | sed -n 1p`"
check "types-widen" "widen: 7" "`echo "$out" | sed -n 2p`"
check "types-opaque" "opaque: 42 empty" "`echo "$out" | sed -n 3p`"
check "types-ret" "ret: 5" "`echo "$out" | sed -n 4p`"
# type hints are CHECKED where both sides are concrete
printf 'local x : int = "bad"\n' > /tmp/catscript_badtype.cat