Skip to content

Strange lack of subtyping for case-> #1337

@LiberalArtist

Description

@LiberalArtist

On Racket 8.9 CS, this program:

#lang typed/racket

(: f (case->
      (-> 'a 'b)
      (-> 'x 'y)))
(define (f arg)
  (if (eq? 'a arg)
      'b
      'y))

(: a->b (-> 'a 'b))
(define a->b f)

(: x->y (-> 'x 'y))
(define x->y f)

(: x/y->a/b (-> (U 'a 'x) (U 'b 'y)))
(define x/y->a/b f)

fails to typecheck with the error:

Type Checker: type mismatch
  expected: (-> (U 'a 'x) (U 'b 'y))
  given: (case-> (-> 'a 'b) (-> 'x 'y)) in: f

Adding an additional case-> clause can get the program to typecheck:

#lang typed/racket

(: f (case->
      (-> 'a 'b)
      (-> 'x 'y)
      (-> (U 'a 'x) (U 'b 'y))))
(define (f arg)
  (if (eq? 'a arg)
      'b
      'y))

(: a->b (-> 'a 'b))
(define a->b f)

(: x->y (-> 'x 'y))
(define x->y f)

(: x/y->a/b (-> (U 'a 'x) (U 'b 'y)))
(define x/y->a/b f)

I think (-> (U 'a 'x) (U 'b 'y)) should be recognized as a subtype of (case-> (-> 'a 'b) (-> 'x 'y)). I don't know if the implementation issues are related, but the symptoms resemble #1321.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions