Check kw functions with optional arguments better
In particular, allow the optional kws to be left out in the expected type (a function type with fewer optional kws is a supertype). Closes PR 14583
This commit is contained in:
parent
22b7cc6a5e
commit
8755e62556
|
@ -134,19 +134,20 @@
|
|||
;; -> (Listof Keyword)
|
||||
;; Remove keywords in the given list that aren't in the actual lambda
|
||||
;; keywords list. This allows the typechecker to check some branches of the
|
||||
;; type that match the actual kws. Add extra actual mandatory keywords
|
||||
;; with Bottom type.
|
||||
;; type that match the actual kws. Add extra actual keywords with Bottom type.
|
||||
(define (handle-extra-or-missing-kws kws actual-kws)
|
||||
(match-define (lambda-kws actual-mands actual-opts) actual-kws)
|
||||
(define expected-mands (map Keyword-kw (filter Keyword-required? kws)))
|
||||
(define expected-kws (map Keyword-kw kws))
|
||||
(define missing-removed
|
||||
(filter
|
||||
(λ (kw) (or (member (Keyword-kw kw) actual-mands)
|
||||
(member (Keyword-kw kw) actual-opts)))
|
||||
kws))
|
||||
(append missing-removed
|
||||
(for/list ([kw (in-list (set-subtract actual-mands expected-mands))])
|
||||
(make-Keyword kw -Bottom #t))))
|
||||
(for/list ([kw (in-list (set-subtract actual-mands expected-kws))])
|
||||
(make-Keyword kw -Bottom #t))
|
||||
(for/list ([kw (in-list (set-subtract actual-opts expected-kws))])
|
||||
(make-Keyword kw -Bottom #f))))
|
||||
|
||||
;; inner-kw-convert : (Listof arr) (Option LambdaKeywords) Boolean -> Type
|
||||
;; Helper function that converts each arr to a Function type and then
|
||||
|
|
|
@ -3080,6 +3080,20 @@
|
|||
(tr:define (f #:foo [foo 'foo] #:bar bar) 0)
|
||||
(error "dummy"))
|
||||
#:msg #rx"too many mandatory keyword arguments.*#:foo"]
|
||||
|
||||
;; PR 14583
|
||||
[tc-e
|
||||
(let ()
|
||||
(: f (-> String))
|
||||
(tr:define (f #:foo [foo 'foo]) "foo")
|
||||
(f))
|
||||
-String]
|
||||
[tc-err
|
||||
(let ()
|
||||
(: f (-> String))
|
||||
(tr:define (f #:foo [foo 'foo]) foo)
|
||||
(error "dummy"))
|
||||
#:msg #rx"expected: String.*given: 'foo"]
|
||||
)
|
||||
|
||||
(test-suite
|
||||
|
|
Loading…
Reference in New Issue
Block a user