diff options
author | David Thompson <dthompson2@worcester.edu> | 2023-01-25 08:40:38 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2023-06-08 08:14:41 -0400 |
commit | e3e7a3f8c1b35af4e16b13c9aa64c1748f81886f (patch) | |
tree | 6c72efd15e5d6529555274a1818de243213e3e20 | |
parent | c4dd6db788d1c4ad27efc86a5f3337f9011b5142 (diff) |
Add exception type for type errors.
-rw-r--r-- | chickadee/graphics/seagull.scm | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/chickadee/graphics/seagull.scm b/chickadee/graphics/seagull.scm index d1a90da..e1db052 100644 --- a/chickadee/graphics/seagull.scm +++ b/chickadee/graphics/seagull.scm @@ -1333,7 +1333,7 @@ (define (unify:primitives a b success) (if (equal? a b) (success '()) - (unify:fail "type mismatch" a b))) + (unify:fail "primitive type mismatch" a b))) (define (unify:variable a b success) (cond @@ -1579,6 +1579,15 @@ (resolve:list exps env)) (_ exp))) +(define &seagull-type-error + (make-exception-type '&seagull-type-error &error '())) + +(define make-seagull-type-error + (record-constructor &seagull-type-error)) + +;; TODO: Add some kind of context object that is threaded through the +;; inference process so that when a type error occurs we can show the +;; expression that caused it. (define (infer-types exp stage) (call-with-unify-rollback (lambda () @@ -1587,8 +1596,15 @@ '() (lambda (subs) (resolve annotated subs))))) - (lambda args - (apply error args)))) + (match-lambda* + ((msg . args) + (raise-exception + (make-exception + (make-seagull-type-error) + (make-exception-with-origin infer-types) + (make-exception-with-message + (format #f "seagull type error: ~a" msg)) + (make-exception-with-irritants args))))))) ;;; |