HS: type-check : returns the value (not a bool) — +2 typecheck

`'foo' : String` and `'foo' : String!` were returning `true` because
`hs-type-check` was a predicate. Per upstream hyperscript semantics,
`value : Type` is a type-asserted pass-through:
- nil passes the basic check (use `Type!` for non-null)
- mismatched type → raise "Typecheck failed!"
- match → return the original value

`hs-type-check-strict` now also raises on nil rather than returning
false, so the `String!` form actually rejects null.

hs-upstream-expressions/typecheck: 0/5 → 2/5.
asExpression unchanged (uses different `as Type` runtime path).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-23 11:14:09 +00:00
parent 1bdd141178
commit 781e0d427a
2 changed files with 22 additions and 28 deletions

View File

@@ -775,25 +775,22 @@
(value type-name)
(if
(nil? value)
true
(cond
((= type-name "Number") (number? value))
((= type-name "String") (string? value))
((= type-name "Boolean") (or (= value true) (= value false)))
((= type-name "Array") (list? value))
((= type-name "Object") (dict? value))
((= type-name "Element") (= (host-typeof value) "element"))
((= type-name "Node")
(or
(= (host-typeof value) "element")
(= (host-typeof value) "text")))
(true (= (host-typeof value) (downcase type-name)))))))
value
(let
((matches (cond ((= type-name "Number") (number? value)) ((= type-name "String") (string? value)) ((= type-name "Boolean") (or (= value true) (= value false))) ((= type-name "Array") (list? value)) ((= type-name "Object") (dict? value)) ((= type-name "Element") (= (host-typeof value) "element")) ((= type-name "Node") (or (= (host-typeof value) "element") (= (host-typeof value) "text"))) (true (= (host-typeof value) (downcase type-name))))))
(if
matches
value
(raise (str "Typecheck failed! expected " type-name)))))))
(define
hs-type-check-strict
(fn
(value type-name)
(if (nil? value) false (hs-type-check value type-name))))
(if
(nil? value)
(raise (str "Typecheck failed! expected " type-name " but got nil"))
(hs-type-check value type-name))))
(define
hs-strict-eq