Avoid wrapping 5 when contracted as (Sequenceof Integer)

Closes racket/math#13
This commit is contained in:
Sam Tobin-Hochstadt 2017-11-08 09:49:22 -05:00 committed by Andrew Kent
parent 966845304e
commit f35a6fd5cb
2 changed files with 25 additions and 1 deletions

View File

@ -10,7 +10,7 @@
(env type-name-env row-constraint-env)
(rep core-rep rep-utils free-ids type-mask values-rep
base-types numeric-base-types)
(types resolve utils printer match-expanders union)
(types resolve utils printer match-expanders union subtype)
(prefix-in t: (types abbrev numeric-tower subtype))
(private parse-type syntax-properties)
racket/match racket/syntax racket/list
@ -525,6 +525,11 @@
[(? Fun? t) (t->sc/fun t)]
[(? DepFun? t) (t->sc/fun t)]
[(Set: t) (set/sc (t->sc t))]
[(Sequence: (list t))
#:when (subtype t:-Nat t)
;; sequence/c is always a wrapper, so avoid it when we just have a number
(or/sc (flat/sc #'exact-nonnegative-integer?)
(sequence/sc (t->sc t)))]
[(Sequence: ts) (apply sequence/sc (map t->sc ts))]
[(Vector: t) (vectorof/sc (t->sc/both t))]
[(HeterogeneousVector: ts) (apply vector/sc (map t->sc/both ts))]

View File

@ -0,0 +1,19 @@
#lang racket/base
(module typed typed/racket/base
(provide foo)
(: foo (-> (U Integer (Sequenceof Integer)) String))
(define (foo x)
(if (integer? x)
(format "I got an integer: ~a" x)
(error "I did not get an integer: ~a" x))))
(module other-typed typed/racket/base
(provide bar)
(require (submod ".." typed))
(define (bar) (foo 0)))
(require 'typed
'other-typed)
(foo 0)
(bar)