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:
1 parent
48b1b84ea6
commit
96e8f516cc
3 files changed
+19
-4
No files matched your search
@@ -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
|
||||
|
||||
@@ -18,3 +18,9 @@ print("widen:", f)
|
||||
local n : cint = 42
|
||||
local buf : cbyte[] = empty
|
||||
print("opaque:", n, buf)
|
||||
|
||||
-- return type hints are checked where concrete
|
||||
function good() -> int
|
||||
return 5
|
||||
end
|
||||
print("ret:", good())
|
||||
Reference in new issue
Block a user