Skip to content

Commit 5482ed7

Browse files
committed
wip
1 parent 7287658 commit 5482ed7

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

typed-racket-lib/typed-racket/typecheck/tc-structs.rkt

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@
379379
(define st-type-alias-maybe-with-proc
380380
(let ([maybe-proc-ty (and (or (Poly? sty) (Struct? sty))
381381
(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)
383384
st-type-alias)) )
384385

385386
;; simple abstraction for handling field getters or setters
@@ -457,7 +458,7 @@
457458
(refine-variance! names stys tvarss))
458459

459460

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)
461462
ty-stx st-name fld-names desc)
462463
(syntax-parse ty-stx
463464
#:literals (struct-field-index)
@@ -474,15 +475,7 @@
474475
max-idx
475476
#:stx ty-stx))
476477
(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)]
486479

487480
;; a field name is provided (via struct-field-index)
488481
[(struct-field-index fld-nm:id)
@@ -517,9 +510,9 @@
517510
"expected" (syntax-e st-name)
518511
"got" n
519512
#: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)))))
523516
arrs))]
524517
[_
525518
(tc-error/fields "type mismatch"
@@ -531,17 +524,42 @@
531524
[_
532525
(customized-proc ty-stx)]))
533526

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))
536529
...)))
537530

538531
(define property-handling-table
539532
(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)
541544
(lambda (ty-stx)
542545
(tc-error/stx ty-stx
543546
"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))))))))
545563

546564

547565

0 commit comments

Comments
 (0)