Fixed printing for new rep.
Handle mandatory and optional keyword args.
This commit is contained in:
parent
79e3a0c4c6
commit
801156229a
|
@ -569,21 +569,35 @@
|
||||||
|
|
||||||
(define (tc-keywords form arities kws kw-args pos-args expected)
|
(define (tc-keywords form arities kws kw-args pos-args expected)
|
||||||
(match arities
|
(match arities
|
||||||
[(list (arr: dom rng rest #f (list (and ktys (Keyword: formal-kws formal-kw-tys (and #f required?))) ...) _ _))
|
[(list (arr: dom rng rest #f ktys _ _))
|
||||||
(for ([k kws]
|
;; assumes that everything is in sorted order
|
||||||
[ty (map tc-expr/t (syntax->list kw-args))])
|
(let loop ([actual-kws kws]
|
||||||
(cond [(for/or ([e ktys])
|
[actuals (map tc-expr/t (syntax->list kw-args))]
|
||||||
(and (eq? (Keyword-kw e) k) e))
|
[formals ktys])
|
||||||
=>
|
(match* (actual-kws formals)
|
||||||
(match-lambda [(Keyword: k kty req?)
|
[('() '())
|
||||||
(unless (subtype ty kty)
|
(void)]
|
||||||
(tc-error/delayed
|
[(_ '())
|
||||||
#:stx form
|
(tc-error/expr #:return (ret (Un))
|
||||||
"Wrong function argument type, expected ~a, got ~a for keyword argument ~a"
|
"Unexpected keyword argument ~a" (car actual-kws))]
|
||||||
kty ty k))])]
|
[('() (cons fst rst))
|
||||||
[else
|
(match fst
|
||||||
(tc-error/expr #:return (ret (Un))
|
[(Keyword: k _ #t)
|
||||||
"function does not accept keyword argument ~a" k)]))
|
(tc-error/expr #:return (ret (Un))
|
||||||
|
"Missing keyword argument ~a" k)]
|
||||||
|
[_ (loop actual-kws actuals rst)])]
|
||||||
|
[((cons k kws-rest) (cons (Keyword: k* t req?) form-rest))
|
||||||
|
(cond [(eq? k k*) ;; we have a match
|
||||||
|
(unless (subtype (car actuals) t)
|
||||||
|
(tc-error/delayed
|
||||||
|
"Wrong function argument type, expected ~a, got ~a for keyword argument ~a"
|
||||||
|
t (car actuals) k))
|
||||||
|
(loop kws-rest (cdr actuals) form-rest)]
|
||||||
|
[req? ;; this keyword argument was required
|
||||||
|
(tc-error/delayed "Missing keyword argument ~a" k*)
|
||||||
|
(loop kws-rest (cdr actuals) form-rest)]
|
||||||
|
[else ;; otherwise, ignore this formal param, and continue
|
||||||
|
(loop actual-kws actuals form-rest)])]))
|
||||||
(tc/funapp (car (syntax-e form)) kw-args (ret (make-Function arities)) (map tc-expr (syntax->list pos-args)) expected)]
|
(tc/funapp (car (syntax-e form)) kw-args (ret (make-Function arities)) (map tc-expr (syntax->list pos-args)) expected)]
|
||||||
[_ (int-err "case-lambda w/ keywords not supported")]))
|
[_ (int-err "case-lambda w/ keywords not supported")]))
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,11 @@
|
||||||
(fp "(")
|
(fp "(")
|
||||||
(for-each (lambda (t) (fp "~a " t)) dom)
|
(for-each (lambda (t) (fp "~a " t)) dom)
|
||||||
(for ([kw kws])
|
(for ([kw kws])
|
||||||
(fp "~a ~a " (car kw) (cdr kw)))
|
(match kw
|
||||||
|
[(Keyword: k t req?)
|
||||||
|
(if req?
|
||||||
|
(fp "~a ~a " k t)
|
||||||
|
(fp "[~a ~a] " k t))]))
|
||||||
(when rest
|
(when rest
|
||||||
(fp "~a* " rest))
|
(fp "~a* " rest))
|
||||||
(when drest
|
(when drest
|
||||||
|
|
Loading…
Reference in New Issue
Block a user