Adjust error messages for : annotation form
Print better error messages for expression like (: 2 Zero). Also fix and improve error messages for multiple/missing types. Closes PR 15044
This commit is contained in:
parent
3e0e3a4005
commit
a80f55946d
|
@ -37,7 +37,8 @@
|
|||
|
||||
(define-syntax (:-helper stx)
|
||||
(syntax-parse stx
|
||||
[(_ _ top-level? i:id ty)
|
||||
[(_ orig-stx top-level? i ty)
|
||||
#:fail-unless (identifier? #'i) (err #'orig-stx "expected identifier" #'i)
|
||||
(unless (or (syntax-e #'top-level?)
|
||||
(identifier-binding #'i))
|
||||
(tc-error/stx #'i
|
||||
|
@ -47,9 +48,9 @@
|
|||
(syntax-property (syntax/loc stx (begin (quote (:-internal i ty))
|
||||
(#%plain-app values)))
|
||||
'disappeared-use #'i)]
|
||||
[(_ orig-stx _ i:id x ...)
|
||||
[(_ orig-stx _ i x ...)
|
||||
#:fail-unless (identifier? #'i) (err #'orig-stx "expected identifier" #'i)
|
||||
(case (syntax-length #'(x ...))
|
||||
[(1) (err #'orig-stx "can only annotate identifiers with types" #'i)]
|
||||
[(0) (err #'orig-stx "missing type")]
|
||||
[else (err #'orig-stx "bad syntax (multiple types after identifier)")])]))
|
||||
[(0) (err #'orig-stx "missing type after identifier")]
|
||||
[else (err #'orig-stx "too many types after identifier")])]))
|
||||
|
||||
|
|
|
@ -20,10 +20,16 @@
|
|||
;; and error checking in primitive macros
|
||||
(define tests
|
||||
(test-suite "Prims tests"
|
||||
(check-bad (let () (: 2 Zero) 'dummy)
|
||||
#rx"expected identifier")
|
||||
(check-bad (let () (: x) 'dummy)
|
||||
#rx"missing type")
|
||||
(check-bad (let () (: x Listof Any) 'dummy)
|
||||
#rx"too many types")
|
||||
(check-bad (let () (: x : Listof Any) 'dummy)
|
||||
#rx"multiple types")
|
||||
#rx"too many types")
|
||||
(check-bad (let () (: x : -> String String) 'dummy)
|
||||
#rx"multiple types")
|
||||
#rx"too many types")
|
||||
(check-ok (let () (: x : String -> String -> String)
|
||||
(define x 0)
|
||||
'dummy))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user