Disallow duplicate type variable declarations
Closes PR 13416 Please merge to 5.3.2
This commit is contained in:
parent
b0f3f03412
commit
9c0a611b59
9
collects/tests/typed-racket/fail/plambda-dup-tvar.rkt
Normal file
9
collects/tests/typed-racket/fail/plambda-dup-tvar.rkt
Normal file
|
@ -0,0 +1,9 @@
|
|||
#;
|
||||
(exn-pred exn:fail:syntax?)
|
||||
#lang typed/racket
|
||||
|
||||
;; don't allow duplicate type variable names
|
||||
|
||||
(plambda: (a a a) ([x : a]) x)
|
||||
(popt-lambda: (a a a) ([x : a]) x)
|
||||
(pcase-lambda: (a a a) ([x : a]) x)
|
8
collects/tests/typed-racket/fail/poly-dup-name.rkt
Normal file
8
collects/tests/typed-racket/fail/poly-dup-name.rkt
Normal file
|
@ -0,0 +1,8 @@
|
|||
#;
|
||||
(exn:pred (lambda (e) (regexp-match? "duplicate type variable" e)))
|
||||
#lang typed/racket
|
||||
|
||||
;; don't allow duplicate type variable names
|
||||
|
||||
(: f (All (A A) (A -> (List A))))
|
||||
(define (f a) (list a))
|
10
collects/tests/typed-racket/fail/polydots-dup-name.rkt
Normal file
10
collects/tests/typed-racket/fail/polydots-dup-name.rkt
Normal file
|
@ -0,0 +1,10 @@
|
|||
#;
|
||||
(exn:pred (lambda (e) (regexp-match? "duplicate type variable or index" e)))
|
||||
#lang typed/racket
|
||||
|
||||
;; don't allow duplicate names in indexes and tvars
|
||||
|
||||
(: f (All (A A ...) (A A ... A -> (List A ... A))))
|
||||
|
||||
(define (f a . xs)
|
||||
(map (λ: ([x : A]) a) xs))
|
|
@ -311,6 +311,8 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
|||
(define-syntax (plambda: stx)
|
||||
(syntax-parse stx
|
||||
[(plambda: (tvars:id ...) formals . body)
|
||||
#:fail-when (check-duplicate-identifier (syntax->list #'(tvars ...)))
|
||||
"duplicate type variable declaration"
|
||||
(quasisyntax/loc stx
|
||||
(#%expression
|
||||
#,(syntax-property (syntax/loc stx (lambda: formals . body))
|
||||
|
@ -320,6 +322,8 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
|||
(define-syntax (pcase-lambda: stx)
|
||||
(syntax-parse stx
|
||||
[(pcase-lambda: (tvars:id ...) cl ...)
|
||||
#:fail-when (check-duplicate-identifier (syntax->list #'(tvars ...)))
|
||||
"duplicate type variable declaration"
|
||||
(quasisyntax/loc stx
|
||||
(#%expression
|
||||
#,(syntax-property (syntax/loc stx (case-lambda: cl ...))
|
||||
|
@ -329,6 +333,8 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
|||
(define-syntax (popt-lambda: stx)
|
||||
(syntax-parse stx
|
||||
[(popt-lambda: (tvars:id ...) formals . body)
|
||||
#:fail-when (check-duplicate-identifier (syntax->list #'(tvars ...)))
|
||||
"duplicate type variable declaration"
|
||||
(quasisyntax/loc stx
|
||||
(#%expression
|
||||
#,(syntax-property (syntax/loc stx (opt-lambda: formals . body))
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
;(printf "parse-all-type: ~a \n" (syntax->datum stx))
|
||||
(syntax-parse stx #:literals (t:All)
|
||||
[((~and kw t:All) (vars:id ... v:id dd:ddd) . t)
|
||||
(when (check-duplicate-identifier (syntax->list #'(vars ... v)))
|
||||
(tc-error "All: duplicate type variable or index"))
|
||||
(let* ([vars (map syntax-e (syntax->list #'(vars ...)))]
|
||||
[v (syntax-e #'v)])
|
||||
(add-disappeared-use #'kw)
|
||||
|
@ -58,6 +60,8 @@
|
|||
(extend-tvars vars
|
||||
(make-PolyDots (append vars (list v)) (parse-all-body #'t)))))]
|
||||
[((~and kw t:All) (vars:id ...) . t)
|
||||
(when (check-duplicate-identifier (syntax->list #'(vars ...)))
|
||||
(tc-error "All: duplicate type variable"))
|
||||
(let* ([vars (map syntax-e (syntax->list #'(vars ...)))])
|
||||
(add-disappeared-use #'kw)
|
||||
(extend-tvars vars
|
||||
|
|
Loading…
Reference in New Issue
Block a user