Fix for*/fold and for*/lists

Only parse and use the type annotations if they are present on
all fold variables. This matches the default for other forms in TR.
Also, this will usually result in a "insufficient type information"
message which is more helpful than if TR chose some default type.

Closes PR 15138
Closes PR 14893
This commit is contained in:
Asumu Takikawa 2015-08-25 01:43:16 -04:00
parent 9fb79b4e18
commit f5f84c7625
2 changed files with 25 additions and 12 deletions

View File

@ -481,14 +481,17 @@ the typed racket language.
clause:for-clauses
a2:optional-standalone-annotation*
c ...)
(define all-typed? (andmap values (attribute var.ty)))
(define for-stx
(quasisyntax/loc stx
(for/lists (var.ann-name ...)
(clause.expand* ... ...)
c ...)))
((attribute a1.annotate)
((attribute a2.annotate)
(add-ann
(quasisyntax/loc stx
(for/lists (var.ann-name ...)
(clause.expand* ... ...)
c ...))
#'(values var.ty ...))))]))
(if all-typed?
(add-ann for-stx #'(values var.ty ...))
for-stx)))]))
(define-syntax (for*/fold: stx)
(syntax-parse stx #:literals (:)
[(_ a1:optional-standalone-annotation*
@ -496,14 +499,17 @@ the typed racket language.
clause:for-clauses
a2:optional-standalone-annotation*
c ...)
(define all-typed? (andmap values (attribute var.ty)))
(define for-stx
(quasisyntax/loc stx
(for/fold ((var.ann-name init) ...)
(clause.expand* ... ...)
c ...)))
((attribute a1.annotate)
((attribute a2.annotate)
(add-ann
(quasisyntax/loc stx
(for/fold ((var.ann-name init) ...)
(clause.expand* ... ...)
c ...))
#'(values var.ty ...))))]))
(if all-typed?
(add-ann for-stx #'(values var.ty ...))
for-stx)))]))
(define-for-syntax (define-for/acc:-variant for*? for/folder: for/folder op initial final)
(lambda (stx)

View File

@ -3783,6 +3783,13 @@
[tc-err (let ()
(define x (eval 0))
x)]
;; PR 15138
[tc-e (for*/lists: ((xs : (Listof Symbol))) ((x '(a b c))) x)
#:ret (ret (-lst -Symbol) (-FS -top -bot) -empty-obj)]
[tc-e (for*/fold: ((xs : (Listof Symbol) '())) ((x '(a b c)))
(cons x xs))
(-lst -Symbol)]
)
(test-suite