Control multiple errors with a parameter.
Don't use same code for handling type ascription and annotation. svn: r9529
This commit is contained in:
parent
2837df70a6
commit
1d21ec5dda
|
@ -78,9 +78,7 @@
|
||||||
ty (Poly-n ty) (length (syntax->list inst)))]
|
ty (Poly-n ty) (length (syntax->list inst)))]
|
||||||
[else
|
[else
|
||||||
(let ([ty* (if inst
|
(let ([ty* (if inst
|
||||||
(begin
|
(instantiate-poly ty (map parse-type (syntax->list inst)))
|
||||||
(printf/log "Type Instantiation: ~a~n" (syntax-e id))
|
|
||||||
(instantiate-poly ty (map parse-type (syntax->list inst))))
|
|
||||||
ty)])
|
ty)])
|
||||||
(ret ty* (list (make-Var-True-Effect id)) (list (make-Var-False-Effect id))))])))
|
(ret ty* (list (make-Var-True-Effect id)) (list (make-Var-False-Effect id))))])))
|
||||||
|
|
||||||
|
@ -142,7 +140,8 @@
|
||||||
[(#%variable-reference . _)
|
[(#%variable-reference . _)
|
||||||
(tc-error/expr #:return (ret expected) "#%variable-reference is not supported by Typed Scheme")]
|
(tc-error/expr #:return (ret expected) "#%variable-reference is not supported by Typed Scheme")]
|
||||||
;; identifiers
|
;; identifiers
|
||||||
[x (identifier? #'x) (check-below (tc-id #'x) expected)]
|
[x (identifier? #'x)
|
||||||
|
(check-below (tc-id #'x) expected)]
|
||||||
;; w-c-m
|
;; w-c-m
|
||||||
[(with-continuation-mark e1 e2 e3)
|
[(with-continuation-mark e1 e2 e3)
|
||||||
(begin (tc-expr/check #'e1 Univ)
|
(begin (tc-expr/check #'e1 Univ)
|
||||||
|
@ -277,8 +276,7 @@
|
||||||
(unless (syntax? form)
|
(unless (syntax? form)
|
||||||
(int-err "bad form input to tc-expr: ~a" form))
|
(int-err "bad form input to tc-expr: ~a" form))
|
||||||
;; typecheck form
|
;; typecheck form
|
||||||
(cond [(type-annotation form) => (lambda (ann)
|
(cond [(type-ascription form) => (lambda (ann)
|
||||||
;(printf "annotated~n")
|
|
||||||
(tc-expr/check form ann))]
|
(tc-expr/check form ann))]
|
||||||
[else (internal-tc-expr form)])))
|
[else (internal-tc-expr form)])))
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,12 @@
|
||||||
(unless (null? stxs)
|
(unless (null? stxs)
|
||||||
(raise-typecheck-error "Errors encountered" (apply append stxs))))]))
|
(raise-typecheck-error "Errors encountered" (apply append stxs))))]))
|
||||||
|
|
||||||
|
(define delay-errors? (make-parameter #t))
|
||||||
|
|
||||||
(define (tc-error/delayed msg #:stx [stx (current-orig-stx)] . rest)
|
(define (tc-error/delayed msg #:stx [stx (current-orig-stx)] . rest)
|
||||||
(set! delayed-errors (cons (make-err (apply format msg rest) (list (locate-stx stx))) delayed-errors)))
|
(if (delay-errors?)
|
||||||
|
(set! delayed-errors (cons (make-err (apply format msg rest) (list (locate-stx stx))) delayed-errors))
|
||||||
|
(raise-typecheck-error (apply format msg rest) (list (locate-stx stx)))))
|
||||||
|
|
||||||
;; produce a type error, using the current syntax
|
;; produce a type error, using the current syntax
|
||||||
(define (tc-error msg . rest)
|
(define (tc-error msg . rest)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
get-type/infer
|
get-type/infer
|
||||||
type-label-symbol
|
type-label-symbol
|
||||||
type-ascrip-symbol
|
type-ascrip-symbol
|
||||||
|
type-ascription
|
||||||
check-type)
|
check-type)
|
||||||
|
|
||||||
(define type-label-symbol 'type-label)
|
(define type-label-symbol 'type-label)
|
||||||
|
@ -23,7 +24,7 @@
|
||||||
|
|
||||||
;; get the type annotation of this syntax
|
;; get the type annotation of this syntax
|
||||||
;; syntax -> Maybe[Type]
|
;; syntax -> Maybe[Type]
|
||||||
(define (type-annotation stx)
|
(define (type-annotation stx #:infer [let-binding #f])
|
||||||
(define (pt prop)
|
(define (pt prop)
|
||||||
(print-size prop)
|
(print-size prop)
|
||||||
(if (syntax? prop)
|
(if (syntax? prop)
|
||||||
|
@ -32,13 +33,24 @@
|
||||||
(cond
|
(cond
|
||||||
[(syntax-property stx type-label-symbol) => pt]
|
[(syntax-property stx type-label-symbol) => pt]
|
||||||
[(syntax-property stx type-ascrip-symbol) => pt]
|
[(syntax-property stx type-ascrip-symbol) => pt]
|
||||||
[(and (identifier? stx) (lookup-type stx (lambda () #f)))
|
;; this is so that : annotation works in internal def ctxts
|
||||||
|
[(and let-binding (identifier? stx) (lookup-type stx (lambda () #f)))
|
||||||
=>
|
=>
|
||||||
(lambda (t)
|
(lambda (t)
|
||||||
(maybe-finish-register-type stx)
|
(maybe-finish-register-type stx)
|
||||||
t)]
|
t)]
|
||||||
[else #f]))
|
[else #f]))
|
||||||
|
|
||||||
|
(define (type-ascription stx)
|
||||||
|
(define (pt prop)
|
||||||
|
(print-size prop)
|
||||||
|
(if (syntax? prop)
|
||||||
|
(parse-type prop)
|
||||||
|
(parse-type/id stx prop)))
|
||||||
|
(cond
|
||||||
|
[(syntax-property stx type-ascrip-symbol) => pt]
|
||||||
|
[else #f]))
|
||||||
|
|
||||||
(define (log/ann stx ty)
|
(define (log/ann stx ty)
|
||||||
(printf/log "Required Annotated Variable: ~a ~a~n" (syntax-e stx) ty))
|
(printf/log "Required Annotated Variable: ~a ~a~n" (syntax-e stx) ty))
|
||||||
(define (log/extra stx ty ty2)
|
(define (log/extra stx ty ty2)
|
||||||
|
@ -72,7 +84,8 @@
|
||||||
[else (log/noann stx ty) ty]))
|
[else (log/noann stx ty) ty]))
|
||||||
stx ty)]
|
stx ty)]
|
||||||
[(list (list stx) ty)
|
[(list (list stx) ty)
|
||||||
(cond [(type-annotation stx) => (lambda (ann)
|
(cond [(type-annotation stx #:infer #t)
|
||||||
|
=> (lambda (ann)
|
||||||
(check-type stx ty ann)
|
(check-type stx ty ann)
|
||||||
(log/extra stx ty ann)
|
(log/extra stx ty ann)
|
||||||
(list ann))]
|
(list ann))]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user