diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-funapp.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-funapp.rkt index f5aea2d3..e81770c4 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-funapp.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-funapp.rkt @@ -173,9 +173,9 @@ (tc/funapp f-stx args-stx (ret (resolve-once t) f o) argtys expected)] ;; a union of functions can be applied if we can apply all of the elements [((tc-result1: (Union: (and ts (list (Function: _) ...)))) _) - (ret (for/fold ([result (Un)]) ([fty (in-list ts)]) - (match (tc/funapp f-stx args-stx (ret fty) argtys expected) - [(tc-result1: t) (Un result t)])))] + (merge-tc-results + (for/list ([fty ts]) + (tc/funapp f-stx args-stx (ret fty) argtys expected)))] ;; error type is a perfectly good fcn type [((tc-result1: (Error:)) _) (ret (make-Error))] ;; otherwise fail diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt index 9bf2359f..1421f662 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt @@ -3007,6 +3007,20 @@ #:ret (ret (-seq (-vec Univ))) #:expected (ret (-seq (-vec Univ)))] + ;; PR 14557 - apply union of functions with different return values + [tc-err + (let () + (: f (U (-> Void) (-> (values Void Void)))) + (define (f) (void)) + (f)) + #:msg #rx"Expected the same number of values.*1 and 2"] + [tc-e + (let () + (: f (U (-> (values String Symbol)) (-> (values Void Void)))) + (define (f) (values "foo" 'bar)) + (f)) + #:ret (ret (list (t:Un -String -Void) (t:Un -Symbol -Void)))] + ) (test-suite