Skip to content

Commit 3738c98

Browse files
committed
Avoid wrapping 5 when contracted as (Sequenceof Integer).
Closes racket/math#13
1 parent 0f733e2 commit 3738c98

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

typed-racket-lib/typed-racket/private/type-contract.rkt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(env type-name-env row-constraint-env)
1111
(rep core-rep rep-utils free-ids type-mask values-rep
1212
base-types numeric-base-types)
13-
(types resolve utils printer match-expanders union)
13+
(types resolve utils printer match-expanders union subtype)
1414
(prefix-in t: (types abbrev numeric-tower subtype))
1515
(private parse-type syntax-properties)
1616
racket/match racket/syntax racket/list
@@ -526,6 +526,11 @@
526526
[(? Fun? t) (t->sc/fun t)]
527527
[(? DepFun? t) (t->sc/fun t)]
528528
[(Set: t) (set/sc (t->sc t))]
529+
[(Sequence: (list t))
530+
#:when (subtype t:-Nat t)
531+
;; sequence/c is always a wrapper, so avoid it when we just have a number
532+
(or/sc (flat/sc #'exact-nonnegative-integer?)
533+
(sequence/sc (t->sc t)))]
529534
[(Sequence: ts) (apply sequence/sc (map t->sc ts))]
530535
[(Vector: t) (vectorof/sc (t->sc/both t))]
531536
[(HeterogeneousVector: ts) (apply vector/sc (map t->sc/both ts))]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#lang racket/base
2+
3+
(module typed typed/racket/base
4+
(provide foo)
5+
(: foo (-> (U Integer (Sequenceof Integer)) String))
6+
(define (foo x)
7+
(if (integer? x)
8+
(format "I got an integer: ~a" x)
9+
(error "I did not get an integer: ~a" x))))
10+
11+
(module other-typed typed/racket/base
12+
(provide bar)
13+
(require (submod ".." typed))
14+
(define (bar) (foo 0)))
15+
16+
(require 'typed
17+
'other-typed)
18+
(foo 0)
19+
(bar)

0 commit comments

Comments
 (0)