[racket] Typed classes: how to send to a value with union type

From: Neil Toronto (neil.toronto at gmail.com)
Date: Tue Aug 19 13:32:55 EDT 2014

I'm making a snip in Typed Racket. I have essentially this:

   (define admin (send this get-admin))
   (define editor (and admin (send admin get-editor)))
   (when editor
     (send editor set-caret-owner #f))

I get this error:

   Type Checker: send: type mismatch
     expected: an object
     given: (U (Instance Text%) (Instance Pasteboard%)) in:
       (send editor set-caret-owner #f)

It's unexpected in the first place because text% and pasteboard% both 
implement editor<%>. Guarding with (is-a? editor text%) doesn't work. 
Casting doesn't work because TR can't generate a contract. How do I do this?

Neil ⊥

Posted on the users mailing list.