mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-22 03:30:22 +02:00
Add support for keyword arguments in `arity-mismatch-analysis'.
* module/language/tree-il/analyze.scm (validate-arity)[filter-keyword-args]: New procedure. [arity]: Get accurate arity for programs, return ALLOW-OTHER-KEYS? as an additional value. Update to `arity' change; use `filter-keyword-args'. * test-suite/tests/tree-il.test ("warnings")["arity mismatch"]("keyword not passed and quiet", "keyword passed and quiet", "keyword passed to global and quiet", "extra keyword", "extra keywords allowed"): New tests.
This commit is contained in:
parent
5658035c9c
commit
af5ed54927
2 changed files with 96 additions and 25 deletions
|
@ -808,4 +808,50 @@
|
|||
(define (foo x) (cons))")))
|
||||
(read-and-compile in
|
||||
#:opts %opts-w-arity
|
||||
#:to 'assembly))))))))
|
||||
#:to 'assembly))))))
|
||||
|
||||
(pass-if "keyword not passed and quiet"
|
||||
(null? (call-with-warnings
|
||||
(lambda ()
|
||||
(compile '(let ((f (lambda* (x #:key y) y)))
|
||||
(f 2))
|
||||
#:opts %opts-w-arity
|
||||
#:to 'assembly)))))
|
||||
|
||||
(pass-if "keyword passed and quiet"
|
||||
(null? (call-with-warnings
|
||||
(lambda ()
|
||||
(compile '(let ((f (lambda* (x #:key y) y)))
|
||||
(f 2 #:y 3))
|
||||
#:opts %opts-w-arity
|
||||
#:to 'assembly)))))
|
||||
|
||||
(pass-if "keyword passed to global and quiet"
|
||||
(null? (call-with-warnings
|
||||
(lambda ()
|
||||
(let ((in (open-input-string "
|
||||
(use-modules (system base compile))
|
||||
(compile '(+ 2 3) #:env (current-module))")))
|
||||
(read-and-compile in
|
||||
#:opts %opts-w-arity
|
||||
#:to 'assembly))))))
|
||||
|
||||
(pass-if "extra keyword"
|
||||
(let ((w (call-with-warnings
|
||||
(lambda ()
|
||||
(compile '(let ((f (lambda* (x #:key y) y)))
|
||||
(f 2 #:Z 3))
|
||||
#:opts %opts-w-arity
|
||||
#:to 'assembly)))))
|
||||
(and (= (length w) 1)
|
||||
(number? (string-contains (car w)
|
||||
"wrong number of arguments to")))))
|
||||
|
||||
(pass-if "extra keywords allowed"
|
||||
(null? (call-with-warnings
|
||||
(lambda ()
|
||||
(compile '(let ((f (lambda* (x #:key y #:allow-other-keys)
|
||||
y)))
|
||||
(f 2 #:Z 3))
|
||||
#:opts %opts-w-arity
|
||||
#:to 'assembly)))))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue