~ chicken-core (chicken-5) b6add5383f325c864dda2fcee3046eda6d94cb2b
commit b6add5383f325c864dda2fcee3046eda6d94cb2b
Author: Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Fri Nov 15 20:04:39 2013 +0100
Commit: Evan Hanson <evhan@foldling.org>
CommitDate: Sat Nov 16 08:39:11 2013 +1300
Warn on cond clauses following constant expressions like for `else'.
Thanks to Joerg Wittenberger for suggestion and initial patch.
Signed-off-by: Evan Hanson <evhan@foldling.org>
diff --git a/expand.scm b/expand.scm
index 5025bc99..a80eeff3 100644
--- a/expand.scm
+++ b/expand.scm
@@ -1144,12 +1144,23 @@
(##sys#check-syntax 'cond clause '#(_ 1))
(cond (else?
(##sys#warn
- "clause following `else' clause in `cond'"
+ (sprintf "clause following `~S' clause in `cond'" else?)
(##sys#strip-syntax clause))
- (expand rclauses #t)
+ (expand rclauses else?)
'(##core#begin))
- ((c %else (car clause))
- (expand rclauses #t)
+ ((or (c %else (car clause))
+ (eq? #t (car clause))
+ ;; Like "constant?" from support.scm
+ (number? (car clause))
+ (char? (car clause))
+ (string? (car clause))
+ (eof-object? (car clause))
+ (blob? (car clause))
+ (vector? (car clause))
+ (##sys#srfi-4-vector? (car clause))
+ (and (pair? (car clause))
+ (c (r 'quote) (caar clause))))
+ (expand rclauses (strip-syntax (car clause)))
`(##core#begin ,@(cdr clause)))
((null? (cdr clause))
`(,%or ,(car clause) ,(expand rclauses #f)))
Trap