diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/union.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/union.rkt index 19f67817..16b7b7d4 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/union.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/union.rkt @@ -3,7 +3,7 @@ (require "../utils/utils.rkt" (rep type-rep rep-utils) (prefix-in c: (contract-req)) - (types subtype base-abbrev resolve) + (types subtype base-abbrev resolve current-seen) racket/match racket/list) @@ -21,6 +21,8 @@ ;; a is a Type (not a union type) ;; b is a List[Type] (non overlapping, non Union-types) ;; The output is a non overlapping list of non Union types. +;; The overlapping constraint is lifted if we are in the midst of subtyping. This is because during +;; subtyping calls to subtype are expensive. (define (merge a b) (define b* (make-union* b)) (match* (a b) @@ -32,6 +34,7 @@ ;; so that bad applications are rejected early. (resolve-app-check-error rator rands stx) (cons a b)] + [(_ _) #:when (currently-subtyping?) (cons a b)] [((? (λ _ (subtype a b*))) _) b] [((? (λ _ (subtype b* a))) _) (list a)] [(_ _) (cons a (filter-not (λ (b-elem) (subtype b-elem a)) b))])) diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/pr14582.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/pr14582.rkt new file mode 100644 index 00000000..c1eea266 --- /dev/null +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/pr14582.rkt @@ -0,0 +1,34 @@ +#lang typed/racket/base +(define-type CodeOfBoolean (Code Boolean)) +(define-type CodeOfInteger (Code Integer)) +(define-type CodeOfAny + (U CodeOfInteger + CodeOfBoolean)) + +(define-type (Code Type) + (U Type + (If Type) + (Begin Type))) + + +(struct (Type) If + ([cond : CodeOfBoolean] + [then : (Code Type)] + [else : (Code Type)]) + #:transparent) + + + +(define-type (ListEndingIn ListType EndType) + (U (Pair EndType Null) + (Pair ListType (ListEndingIn ListType EndType)))) + +(struct (Type) Begin + ([exprs : (ListEndingIn CodeOfAny (Code Type))])) + + +(define QuotedCode : CodeOfInteger + (If #t + 1 + (Begin + (list 2 #f (If #t 3 4)))))