diff --git a/collects/tests/typed-racket/unit-tests/subtype-tests.rkt b/collects/tests/typed-racket/unit-tests/subtype-tests.rkt index 64b2553593..ea91f04a2a 100644 --- a/collects/tests/typed-racket/unit-tests/subtype-tests.rkt +++ b/collects/tests/typed-racket/unit-tests/subtype-tests.rkt @@ -170,6 +170,16 @@ [(-HT t1 t2) (-HT t2 t1)] [(make-Prompt-Tagof t1 t2) (make-Prompt-Tagof t2 t1)] [(make-Continuation-Mark-Keyof t1) (make-Continuation-Mark-Keyof t2)] + + [(-val 5) (-seq -Nat)] + [(-val 5) (-seq -Byte)] + [-Index (-seq -Index)] + [-NonNegFixnum (-seq -NonNegFixnum)] + [-Index (-seq -Nat)] + [FAIL (-val -5) (-seq -Nat)] + [FAIL -Fixnum (-seq -Fixnum)] + [FAIL -NonNegFixnum (-seq -Index)] + [FAIL (-val 5.0) (-seq -Nat)] )) (define-go diff --git a/collects/typed-racket/infer/infer-unit.rkt b/collects/typed-racket/infer/infer-unit.rkt index 76db563479..7a95aea1f7 100644 --- a/collects/typed-racket/infer/infer-unit.rkt +++ b/collects/typed-racket/infer/infer-unit.rkt @@ -470,6 +470,26 @@ (cg -Nat t*)] [((Base: 'Input-Port _ _ _ _) (Sequence: (list t*))) (cg -Nat t*)] + [((Value: (? exact-nonnegative-integer? n)) (Sequence: (list t*))) + (define possibilities + (list + (list byte? -Byte) + (list portable-index? -Index) + (list portable-fixnum? -NonNegFixnum) + (list values -Nat))) + (define type + (for/or ((pred-type possibilities)) + (match pred-type + ((list pred? type) + (and (pred? n) type))))) + (cg type t*)] + [((Base: _ _ _ _ #t) (Sequence: (list t*))) + (define type + (for/or ((t (list -Byte -Index -NonNegFixnum -Nat))) + (and (subtype S t) t))) + (if type + (cg type t*) + (fail! S T))] [((Vector: t) (Sequence: (list t*))) (cg t t*)] [((Hashtable: k v) (Sequence: (list k* v*))) diff --git a/collects/typed-racket/types/subtype.rkt b/collects/typed-racket/types/subtype.rkt index b9582d4020..9f7bec985c 100644 --- a/collects/typed-racket/types/subtype.rkt +++ b/collects/typed-racket/types/subtype.rkt @@ -297,6 +297,26 @@ (subtype* A0 -Byte t*)] [((Base: 'Input-Port _ _ _ _) (Sequence: (list t*))) (subtype* A0 -Nat t*)] + [((Value: (? exact-nonnegative-integer? n)) (Sequence: (list t*))) + (define possibilities + (list + (list byte? -Byte) + (list portable-index? -Index) + (list portable-fixnum? -NonNegFixnum) + (list values -Nat))) + (define type + (for/or ((pred-type possibilities)) + (match pred-type + ((list pred? type) + (and (pred? n) type))))) + (subtype* A0 type t*)] + [((Base: _ _ _ _ #t) (Sequence: (list t*))) + (define type + (for/or ((t (list -Byte -Index -NonNegFixnum -Nat))) + (and (subtype s t) t))) + (if type + (subtype* A0 type t*) + (fail! s t))] [((Hashtable: k v) (Sequence: (list k* v*))) (subtypes* A0 (list k v) (list k* v*))] [((Set: t) (Sequence: (list t*)))