diff --git a/collects/typed-scheme/private/type-annotation.ss b/collects/typed-scheme/private/type-annotation.ss index 3da58d45..637574b4 100644 --- a/collects/typed-scheme/private/type-annotation.ss +++ b/collects/typed-scheme/private/type-annotation.ss @@ -9,6 +9,7 @@ scheme/match mzlib/trace) (provide type-annotation get-type + get-types get-type/infer type-label-symbol type-ascrip-symbol @@ -71,17 +72,23 @@ (printf/log "Unannotated Variable: ~a ~a~n" (syntax-e stx) ty)) ;; get the type annotation of this identifier, otherwise error -;; identifier -> Type -(define (get-type stx) +;; if #:default is provided, return that instead of error +;; identifier #:default Type -> Type +(define (get-type stx #:default [default #f]) (parameterize ([current-orig-stx stx]) (cond [(type-annotation stx #:infer #t)] + [default default] [(not (syntax-original? stx)) (tc-error "untyped var: ~a" (syntax-e stx))] [else (tc-error "no type information on variable ~a" (syntax-e stx))]))) +;; Listof[identifer] #:default Type -> Listof[Type] +(define (get-types stxs #:default [default #f]) + (map (lambda (e) (get-type e #:default default)) stxs)) + ;; get the type annotations on this list of identifiers ;; if not all identifiers have annotations, return the supplied inferred type ;; list[identifier] type -> list[type] diff --git a/collects/typed-scheme/typecheck/tc-lambda-unit.ss b/collects/typed-scheme/typecheck/tc-lambda-unit.ss index a4159fb6..66ce8963 100644 --- a/collects/typed-scheme/typecheck/tc-lambda-unit.ss +++ b/collects/typed-scheme/typecheck/tc-lambda-unit.ss @@ -44,7 +44,7 @@ (let* ([arg-len (length arg-list)] [tys-len (length arg-tys)] [arg-types (if (andmap type-annotation arg-list) - (map get-type arg-list) + (get-types arg-list #:default Univ) (cond [(= arg-len tys-len) arg-tys] [(< arg-len tys-len) (take arg-tys arg-len)] @@ -79,14 +79,14 @@ [(dotted? rest) => (lambda (b) - (let ([dty (get-type rest)]) + (let ([dty (get-type rest #:default Univ)]) (with-dotted-env/extend rest dty b (check-body))))] [else (let ([rest-type (cond [rest-ty rest-ty] - [(type-annotation rest) (get-type rest)] + [(type-annotation rest) (get-type rest #:default Univ)] [(< arg-len tys-len) (list-ref arg-tys arg-len)] [else (Un)])]) (with-lexical-env/extend @@ -108,7 +108,7 @@ (syntax-case args () [(args ...) (let* ([arg-list (syntax->list #'(args ...))] - [arg-types (map get-type arg-list)]) + [arg-types (get-types arg-list #:default Univ)]) #;(for-each (lambda (a) (printf/log "Lambda Var: ~a~n" (syntax-e a))) arg-list) (with-lexical-env/extend arg-list arg-types @@ -124,7 +124,7 @@ [t (int-err "bad match - not a tc-result: ~a no ret-ty" t)])))] [(args ... . rest) (let* ([arg-list (syntax->list #'(args ...))] - [arg-types (map get-type arg-list)]) + [arg-types (get-types arg-list #:default Univ)]) #;(for-each (lambda (a) (printf/log "Lambda Var: ~a~n" (syntax-e a))) (cons #'rest arg-list)) (cond [(dotted? #'rest) @@ -138,7 +138,7 @@ (extend-env (list bound) (list (make-DottedBoth (make-F bound))) (current-tvars))]) - (get-type #'rest))]) + (get-type #'rest #:default Univ))]) (with-lexical-env/extend arg-list arg-types @@ -148,7 +148,7 @@ (match-let ([(tc-result: t thn els) (tc-exprs (syntax->list body))]) (make-arr-dots arg-types t rest-type bound))))))] [else - (let ([rest-type (get-type #'rest)]) + (let ([rest-type (get-type #'rest #:default Univ)]) (with-lexical-env/extend (cons #'rest arg-list) (cons (make-Listof rest-type) arg-types)