diff --git a/Assignments/04.rkt b/Assignments/04.rkt index 9b62dfc..286a887 100644 --- a/Assignments/04.rkt +++ b/Assignments/04.rkt @@ -83,14 +83,12 @@ (if (empty? keys) #t (let ([key (first keys)]) - (type-case (Optionof Type) (hash-ref Y-fields key) - [(none) #f] ;; Key not found in Y-fields - [(some Y-type) + (let ([Y-type (some-v (hash-ref Y-fields key))]) (type-case (Optionof Type) (hash-ref X-fields key) [(none) #f] ;; Key not found in X-fields [(some X-type) (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)))] [else #f])])) @@ -322,5 +320,11 @@ (test (subtype? (arrowT hello-goodbye-t hello-goodbye-t) (arrowT hello-t hello-t)) #f) ;; 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? (numT) (arrowT (numT) (numT))) #f)) \ No newline at end of file