finally. part2

This commit is contained in:
Isaac Shoebottom 2025-04-10 08:52:46 -03:00
parent b1cc807d45
commit 14b79a7d2a

View File

@ -83,14 +83,12 @@
(if (empty? keys) (if (empty? keys)
#t #t
(let ([key (first keys)]) (let ([key (first keys)])
(type-case (Optionof Type) (hash-ref Y-fields key) (let ([Y-type (some-v (hash-ref Y-fields key))])
[(none) #f] ;; Key not found in Y-fields
[(some Y-type)
(type-case (Optionof Type) (hash-ref X-fields key) (type-case (Optionof Type) (hash-ref X-fields key)
[(none) #f] ;; Key not found in X-fields [(none) #f] ;; Key not found in X-fields
[(some X-type) [(some X-type)
(and (subtype? X-type Y-type) ;; Check subtyping of field types (and (subtype? X-type Y-type) ;; Check subtyping of field types
(loop (rest keys)))])]))))] ;; Recurse on remaining keys (loop (rest keys)))])))))] ;; Recurse on remaining keys
(loop (hash-keys Y-fields)))] (loop (hash-keys Y-fields)))]
[else #f])])) [else #f])]))
@ -322,5 +320,11 @@
(test (subtype? (arrowT hello-goodbye-t hello-goodbye-t) (test (subtype? (arrowT hello-goodbye-t hello-goodbye-t)
(arrowT hello-t hello-t)) #f) (arrowT hello-t hello-t)) #f)
;; for coverage ;; for coverage
(define non-object-fun `{lam {x : num} {msg x hello}})
;; `x` is bound to `numT`, which is not an object type
(test/exn (tc non-object-fun) "bound variable is not an object")
(test (subtype? hello-t (boolT)) #f)
(test (subtype? (boolT) (boolT)) #t)
(test (subtype? (boolT) (numT)) #f)
(test (subtype? (arrowT (numT) (numT)) (numT)) #f) (test (subtype? (arrowT (numT) (numT)) (numT)) #f)
(test (subtype? (numT) (arrowT (numT) (numT))) #f)) (test (subtype? (numT) (arrowT (numT) (numT))) #f))