- 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.
27 lines
650 B
Plaintext
27 lines
650 B
Plaintext
-- tests/types.cat -- compile-time type checking of hints.
|
|
--
|
|
-- Hints are now CHECKED where both sides are concrete and known; opaque
|
|
-- or unknown names remain permissive (structural typing never rejects a
|
|
-- program by guessing).
|
|
|
|
local x : int = 42
|
|
local y : float = 3.5
|
|
local z : text = "hi"
|
|
local b : bool = true
|
|
print("ok:", x, y, z, b)
|
|
|
|
-- int widens to float
|
|
local f : float = 7
|
|
print("widen:", f)
|
|
|
|
-- opaque type names stay permissive (no false rejection)
|
|
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())
|