From 781e0d427aeafd942d83e45264327c8ba6041b02 Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 23 Apr 2026 11:14:09 +0000 Subject: [PATCH] =?UTF-8?q?HS:=20type-check=20`:`=20returns=20the=20value?= =?UTF-8?q?=20(not=20a=20bool)=20=E2=80=94=20+2=20typecheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `'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) --- lib/hyperscript/runtime.sx | 25 +++++++++++-------------- shared/static/wasm/sx/hs-runtime.sx | 25 +++++++++++-------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/lib/hyperscript/runtime.sx b/lib/hyperscript/runtime.sx index ce30f325..fd276cd1 100644 --- a/lib/hyperscript/runtime.sx +++ b/lib/hyperscript/runtime.sx @@ -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 diff --git a/shared/static/wasm/sx/hs-runtime.sx b/shared/static/wasm/sx/hs-runtime.sx index ce30f325..fd276cd1 100644 --- a/shared/static/wasm/sx/hs-runtime.sx +++ b/shared/static/wasm/sx/hs-runtime.sx @@ -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