Skip to content

Commit

Permalink
Clean up lam-result.
Browse files Browse the repository at this point in the history
Make drest a list instead of a pair, replace an int-err with a match error
which has source location, and remove static name for rest argument in error
case.
(cherry picked from commit 4fcda73)
  • Loading branch information
endobson authored and rmculpepper committed Jul 8, 2013
1 parent 4bae399 commit bd6baad
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions collects/typed-racket/typecheck/tc-lambda-unit.rkt
Expand Up @@ -25,24 +25,23 @@
(define-struct/cond-contract lam-result ([args (listof (list/c identifier? Type/c))]
[kws (listof (list/c keyword? identifier? Type/c boolean?))]
[rest (or/c #f (list/c identifier? Type/c))]
[drest (or/c #f (cons/c identifier? (cons/c Type/c symbol?)))]
[drest (or/c #f (list/c identifier? (cons/c Type/c symbol?)))]
[body tc-results/c])
#:transparent)

(define (lam-result->type lr)
(match lr
[(struct lam-result ((list (list arg-ids arg-tys) ...) (list (list kw kw-id kw-ty req?) ...) rest drest body))
(let ([arg-names (append arg-ids
(if rest (list (car rest)) null)
(if drest (list (car drest)) null)
(if rest (list (first rest)) null)
(if drest (list (first drest)) null)
kw-id)])
(make-arr
arg-tys
(abstract-results body arg-names)
#:kws (map make-Keyword kw kw-ty req?)
#:rest (if rest (second rest) #f)
#:drest (if drest (cdr drest) #f)))]
[_ (int-err "not a lam-result")]))
#:rest (and rest (second rest))
#:drest (and drest (second drest))))]))

(define-syntax-class cl-rhs
#:literals (if)
Expand Down Expand Up @@ -100,7 +99,7 @@
null
(and rest-ty (list (or rest (generate-temporary)) rest-ty))
;; make up a fake name if none exists, this is an error case anyway
(and drest (cons (or rest (generate-temporary)) drest))
(and drest (list (or rest (generate-temporary)) drest))
(tc-exprs/check (syntax->list body) ret-ty))))
;; Check that the number of formal arguments is valid for the expected type.
;; Thus it must be able to accept the number of arguments that the expected
Expand Down Expand Up @@ -218,7 +217,7 @@
combined-args
null
#f
(cons rest-id (cons rest-type bound))
(list rest-id (cons rest-type bound))
(tc-exprs (syntax->list body))))))]
;; Lambda with regular rest argument
[rest-id
Expand Down Expand Up @@ -303,7 +302,8 @@
;; very conservative -- only do anything interesting if we get exactly one thing that matches
[(list)
(if (and (= 1 (length formals*)) expected-type)
(tc-error/expr #:return (list (lam-result null null (list #'here Univ) #f (ret (Un))))
(tc-error/expr #:return (list (lam-result null null (list (generate-temporary) Univ)
#f (ret (Un))))
"Expected a function of type ~a, but got a function with the wrong arity"
expected-type)
(tc/lambda-clause f* b*))]
Expand Down

0 comments on commit bd6baad

Please sign in to comment.