Type checking extracted methods

10/07/2020
by   Yuquan Fu, et al.
0

Many object-oriented dynamic languages allow programmers to extract methods from objects and treat them as functions. This allows for flexible programming patterns, but presents challenges for type systems. In particular, a simple treatment of method extraction would require methods to be contravariant in the reciever type, making overriding all-but-impossible. We present a detailed investigation of this problem, as well as an implemented and evaluated solution. We show how existing gradual type systems such as TypeScript and Flow are unsound in the presence of method extraction. Working in the context of Racket, whose structure system includes a low-level form of methods, we show how to combine two existing type system features—existential types and occurrence typing–to produce a sound approach to typing method extraction. Our design is proved sound, has been implemented and shipped in Typed Racket, and works for existing Racket programs using these features.

READ FULL TEXT

Please sign up or login with your details

Forgot password? Click here to reset