(define (check-case dls env x)
(define (check-match switch-type x)
+
+ (define (get-bindings product-types pattern)
+ (define (go product-type product)
+ (case (ast-type x)
+ ['var (list (cons product product-type))]
+ ; an inner pattern match
+ ['app (get-bindings product-type product)]))
+ (flat-map go product-types (cdr pattern)))
+
+
(let ([pattern (car x)]
[expr (cadr x)])
(case (ast-type pattern)
(let ([sum (assoc (car pattern) (cdr (assoc switch-type dls)))])
(unless sum (error #f "can't pattern match ~a with ~a" switch-type pattern))
(let* ([names (cdr pattern)]
- [types (cdr sum)]
- [new-env (fold-left env-insert env names types)])
+ [product-types (cdr sum)]
+ [new-env (append (get-bindings product-types pattern) env)])
(check dls new-env expr)))]
; pattern match with binding and no constructor
['var (check dls (env-insert env pattern switch-type) expr)]