|
43 | 43 | ;; (i.e. (append positional (or id '())) but syntax)
|
44 | 44 | (struct formals (positional rest syntax) #:transparent)
|
45 | 45 |
|
46 |
| -(define (make-formals stx) |
| 46 | + |
| 47 | +;; When expanding a keyword or optional lambda, Racket adds into the expanded |
| 48 | +;; code more lambdas, where syntax objects for the original lambda's parameters |
| 49 | +;; are reused. Since Typed Racket stores type information stored in the syntax |
| 50 | +;; objects, when the orginal lambda is a polymorphic function, that information |
| 51 | +;; might carry out-of-scope type variables. In this case, we need to remove it |
| 52 | +;; from parameter syntax objects. |
| 53 | +;; |
| 54 | +;; not-in-poly is #t if the original TR function is polymorphic. |
| 55 | +(define (make-formals stx [not-in-poly #t]) |
| 56 | + (define (maybe-remove a) |
| 57 | + (if (and not-in-poly (from-plambda-property a)) |
| 58 | + (syntax-property-remove a 'type-label) |
| 59 | + a)) |
| 60 | + |
47 | 61 | (let loop ([s stx] [acc null])
|
48 | 62 | (cond
|
49 |
| - [(pair? s) (loop (cdr s) (cons (car s) acc))] |
| 63 | + [(pair? s) (loop (cdr s) (cons (maybe-remove (car s)) acc))] |
50 | 64 | [(null? s) (formals (reverse acc) #f stx)]
|
51 |
| - [(pair? (syntax-e s)) (loop (stx-cdr s) (cons (stx-car s) acc))] |
| 65 | + [(pair? (syntax-e s)) (loop (stx-cdr s) (cons (maybe-remove (stx-car s)) acc))] |
52 | 66 | [(null? (syntax-e s)) (formals (reverse acc) #f stx)]
|
53 |
| - [else (formals (reverse acc) s stx)]))) |
| 67 | + [else (formals (reverse acc) (maybe-remove s) stx)]))) |
54 | 68 |
|
55 | 69 | ;; Currently no support for objects representing the rest argument
|
56 | 70 | (define (formals->objects f)
|
|
621 | 635 | (tc-error/expr #:return dep-fun-ty
|
622 | 636 | "Dependent functions must have a single arity.")])))
|
623 | 637 |
|
624 |
| -(define (tc/mono-lambda/type formalss bodies expected) |
| 638 | +(define (tc/mono-lambda/type formalss bodies expected [not-in-poly #t]) |
625 | 639 | (match expected
|
626 | 640 | [(tc-result1:(? DepFun? dep-fun-ty))
|
627 | 641 | (tc/dep-lambda formalss bodies dep-fun-ty)]
|
628 | 642 | [_ (make-Fun
|
629 | 643 | (tc/mono-lambda
|
630 | 644 | (for/list ([f (in-syntax formalss)]
|
631 | 645 | [b (in-syntax bodies)])
|
632 |
| - (cons (make-formals f) b)) |
| 646 | + (cons (make-formals f not-in-poly) b)) |
633 | 647 | expected))]))
|
634 | 648 |
|
635 | 649 | (define (plambda-prop stx)
|
|
678 | 692 | [_
|
679 | 693 | (define remaining-layers (remove-poly-layer tvarss-list))
|
680 | 694 | (if (null? remaining-layers)
|
681 |
| - (tc/mono-lambda/type formals bodies expected) |
| 695 | + (tc/mono-lambda/type formals bodies expected #f) |
682 | 696 | (tc/plambda form remaining-layers formals bodies expected))]))
|
683 | 697 | ;; check the bodies appropriately
|
684 | 698 | ;; and make both annotated and declared type variables point to the
|
|
0 commit comments