File tree Expand file tree Collapse file tree 2 files changed +15
-13
lines changed
typed-racket-lib/typed-racket/types
typed-racket-test/succeed Expand file tree Collapse file tree 2 files changed +15
-13
lines changed Original file line number Diff line number Diff line change 590
590
(cons portable-fixnum? -NonNegFixnum)
591
591
(cons values -Nat)))
592
592
593
+ (define (valid-prop-name? name properties)
594
+ (and (free-id-set-member? properties name) (Struct-Property? (lookup-id-type/lexical name))))
593
595
594
596
(define-rep-switch (subtype-cases A (#:switch t1) t2 obj)
595
597
;; NOTE: keep these in alphabetical order
1201
1203
[(StructTop: (Struct: nm2 _ _ _ _ _ _ ))
1202
1204
#:when (free-identifier=? nm1 nm2)
1203
1205
A]
1204
- [(Has-Struct-Property: prop-name)
1205
- (cond
1206
- [(free-id-set-member? properties prop-name)
1207
- (match (lookup-id-type/lexical prop-name)
1208
- [(? Struct-Property?) A])]
1209
- [else #f ])]
1206
+ [(Has-Struct-Property: prop-name) #:when (valid-prop-name? prop-name properties)
1207
+ A]
1210
1208
[(Val-able: (? (negate struct?) _ )) #f ]
1211
1209
;; subtyping on structs follows the declared hierarchy
1212
1210
[_ (cond
1223
1221
[(case: StructType (StructType: t1*))
1224
1222
(match t2
1225
1223
[(StructTypeTop:) A]
1224
+ [(Has-Struct-Property: prop-name)
1225
+ (match t1*
1226
+ [(Struct: _ _ _ _ _ _ properties) #:when (valid-prop-name? prop-name properties)
1227
+ A]
1228
+ [else #f ])]
1226
1229
[_ (continue<: A t1 t2 obj)])]
1227
1230
[(case: Syntax (Syntax: elem1))
1228
1231
(match t2
Original file line number Diff line number Diff line change 6
6
(: prop-ins-to-num-ref (Some (X) (-> (Has-Struct-Property prop-ins-to-num) (-> X Number) : X) ))
7
7
(define-values (prop-ins-to-num prop-ins-to-num? prop-ins-to-num-ref) (make-struct-type-property 'prop-ins-to-num ))
8
8
9
- ;; (: bar? : Any -> Boolean : (Has-Struct-Property prop-ins-to-num))
10
- ;; (define bar? prop-ins-to-num?)
11
9
12
-
13
- ; (struct (X Y) helloworld ([x : Y] [y : Y]) #:property prop-ins-to-num (cons 20 40))
14
-
15
- (struct posn ([x : Integer] [y : Integer]) #:property prop-ins-to-num (λ ([self : posn])
16
- 20 ))
10
+ (struct posn ([x : Integer] [y : Integer])
11
+ #:property prop-ins-to-num
12
+ (λ ([self : posn])
13
+ 20 ))
17
14
18
15
(: p1 posn)
19
16
(define p1 (posn 100 200 ))
20
17
(posn-x p1)
18
+
19
+ (prop-ins-to-num-ref struct:posn)
21
20
(: val Number)
22
21
(define val ((prop-ins-to-num-ref p1) p1))
You can’t perform that action at this time.
0 commit comments