Issue #336 - Validate num of args passed to if

This commit is contained in:
Justin Ethier 2019-09-04 13:07:02 -04:00
parent b482a40f04
commit 02fa091297
2 changed files with 14 additions and 7 deletions

View file

@ -7,6 +7,7 @@ https://github.com/cyclone-scheme/cyclone-winds
Bug Fixes
- Validate the number of arguments passed to `if` expressions.
- Raise a useful error instead of aborting the whole program (!) when apply attempts to execute an object of the wrong type.
- Better handling of edge cases where an object of the wrong type is executed instead of a closure. Previously there were cases where this would cause the runtime to crash.

View file

@ -547,13 +547,19 @@
'ok))
(define (analyze-if exp a-env rename-env local-renamed)
(let ((pproc (analyze (if-predicate exp) a-env rename-env local-renamed))
(cproc (analyze (if-consequent exp) a-env rename-env local-renamed))
(aproc (analyze (if-alternative exp) a-env rename-env local-renamed)))
(lambda (env)
(if (pproc env)
(cproc env)
(aproc env)))))
(let ((args (length exp)))
(cond
((< args 3)
(error "Not enough arguments" exp))
((> args 4)
(error "Too many arguments" exp)))
(let ((pproc (analyze (if-predicate exp) a-env rename-env local-renamed))
(cproc (analyze (if-consequent exp) a-env rename-env local-renamed))
(aproc (analyze (if-alternative exp) a-env rename-env local-renamed)))
(lambda (env)
(if (pproc env)
(cproc env)
(aproc env))))))
(define (analyze-lambda exp a-env rename-env local-renamed)
(let* ((vars (lambda-parameters exp))