|
379 | 379 | (define st-type-alias-maybe-with-proc
|
380 | 380 | (let ([maybe-proc-ty (and (or (Poly? sty) (Struct? sty))
|
381 | 381 | (Struct-proc sty))])
|
382 |
| - (if maybe-proc-ty (intersect st-type-alias maybe-proc-ty) |
| 382 | + (if maybe-proc-ty |
| 383 | + (intersect st-type-alias maybe-proc-ty) |
383 | 384 | st-type-alias)) )
|
384 | 385 |
|
385 | 386 | ;; simple abstraction for handling field getters or setters
|
|
457 | 458 | (refine-variance! names stys tvarss))
|
458 | 459 |
|
459 | 460 |
|
460 |
| -(define ((make-extract predicate mismatched-field-type-errors customized-proc property-lambda-rng-chck) |
| 461 | +(define ((make-extract check-field-type customized-proc check-doms-rng) |
461 | 462 | ty-stx st-name fld-names desc)
|
462 | 463 | (syntax-parse ty-stx
|
463 | 464 | #:literals (struct-field-index)
|
|
474 | 475 | max-idx
|
475 | 476 | #:stx ty-stx))
|
476 | 477 | (define ty (list-ref (struct-desc-self-fields desc) n))
|
477 |
| - (unless (predicate ty) |
478 |
| - (tc-error/fields |
479 |
| - (format "field ~a is not a ~a" (syntax-e (list-ref fld-names n)) (car mismatched-field-type-errors)) |
480 |
| - "expected" |
481 |
| - (cdr mismatched-field-type-errors) |
482 |
| - "given" |
483 |
| - ty |
484 |
| - #:stx ty-stx)) |
485 |
| - ty] |
| 478 | + (check-field-type ty-stx (list-ref fld-names n) ty)] |
486 | 479 |
|
487 | 480 | ;; a field name is provided (via struct-field-index)
|
488 | 481 | [(struct-field-index fld-nm:id)
|
|
517 | 510 | "expected" (syntax-e st-name)
|
518 | 511 | "got" n
|
519 | 512 | #:stx (st-proc-ty-property #'ty-stx))])
|
520 |
| - (when property-lambda-rng-chck |
521 |
| - (property-lambda-rng-chck rng)) |
522 |
| - (values (cdr doms) rng)))) |
| 513 | + (if check-doms-rng |
| 514 | + (check-doms-rng #'ty-stx (cdr doms) rng) |
| 515 | + (values (cdr doms) rng))))) |
523 | 516 | arrs))]
|
524 | 517 | [_
|
525 | 518 | (tc-error/fields "type mismatch"
|
|
531 | 524 | [_
|
532 | 525 | (customized-proc ty-stx)]))
|
533 | 526 |
|
534 |
| -(define-syntax-rule (define-property-handling-table (name predicate msg-parts custimized-handling rng-chck) ...) |
535 |
| - (make-immutable-free-id-table (list (cons name (make-extract predicate msg-parts custimized-handling rng-chck)) |
| 527 | +(define-syntax-rule (define-property-handling-table (name check-field-type custimized-handling rng-chck) ...) |
| 528 | + (make-immutable-free-id-table (list (cons name (make-extract check-field-type custimized-handling rng-chck)) |
536 | 529 | ...)))
|
537 | 530 |
|
538 | 531 | (define property-handling-table
|
539 | 532 | (define-property-handling-table
|
540 |
| - (#'prop:procedure Fun? (cons "function" "Procedure") |
| 533 | + (#'prop:procedure |
| 534 | + (lambda (ty-stx fld-name ty) |
| 535 | + (unless (Fun? ty) |
| 536 | + (tc-error/fields |
| 537 | + (format "field ~a is not a function" (syntax-e fld-name)) |
| 538 | + "expected" |
| 539 | + "Procedure" |
| 540 | + "given" |
| 541 | + ty |
| 542 | + #:stx ty-stx)) |
| 543 | + ty) |
541 | 544 | (lambda (ty-stx)
|
542 | 545 | (tc-error/stx ty-stx
|
543 | 546 | "expected: a nonnegative integer literal or an annotated lambda"))
|
544 |
| - #f))) |
| 547 | + #f) |
| 548 | + (#'prop:evt? |
| 549 | + (lambda (ty-stx field-name ty) |
| 550 | + (if (Evt? ty) |
| 551 | + ty |
| 552 | + (make-Evt (Un)))) |
| 553 | + (lambda (ty-stx) |
| 554 | + (tc-error/stx ty-stx |
| 555 | + "expected: a nonnegative integer literal, an annotated lambda that returns an event, or an event")) |
| 556 | + (lambda (ty-stx doms rng) |
| 557 | + (unless (zero? (length doms)) |
| 558 | + (tc-error/stx ty-stx |
| 559 | + "expected: a function that takes only one argument")) |
| 560 | + (if (Evt? rng) |
| 561 | + (values doms rng) |
| 562 | + (values doms (-mu x (make-Evt x)))))))) |
545 | 563 |
|
546 | 564 |
|
547 | 565 |
|
|
0 commit comments