[type (data-tor-type data-layouts sum-name)]
- [sum (assoc sum-name (cdr (assoc type data-layouts)))]
+ [sums (cdr (assoc type data-layouts))]
+ [sum (assoc sum-name sums)]
[expected-number (length (cdr sum))])
+ ; assert that we only do a let pattern match on an ADT with exactly one sum
+ (when (not (= 1 (length sums)))
+ (error #f (format "Cannot pattern match a ~a in a let since it has ~a possible constructors"
+ type
+ (length sums))))
+
; assert that there is the correct number of bindings
(when (not (= (length products)
expected-number))
(test-types
(typecheck
- '((data A
- [foo Int]
- [bar Bool])
+ '((data A [foo Int])
(let ([x (foo 42)]
[(foo y) x])
x)))
(test-types
(typecheck
- '((data A
- [foo Int]
- [bar Bool])
+ '((data A [foo Int])
(let ([x (foo 42)]
[(foo y) x])
y)))
(let ([(foo x y) (foo (= 3 3) 42)])
y))
42)
+
+(test-exception (expand-pattern-matches
+ '((data A [foo Int]
+ [bar Bool])
+ (let ([(foo x) (foo 0)]) x))))