Type Checking for Object Oriented Features

Type checking is the activity of ensuring that the operands of an operator are of compatible types. This post is about how object oriented features such as inheritance, overloading and overriding affect type checking.

A type error occurs when an argument of an unexpected type is given to an operation. It can be signalled at compile time or at run time.

Need to consider shape of class hierarchies.
When the least upper bound of A and B exists, we denote it A ∐ B.

Function overloading:
At compile-time, determine which function is meant by inspecting the types of the arguments.
Report an error if no one function is the best function.

Function overriding:
Determine at run-time based on real object.

In some languages like C++ and Java, it is possible to treat arrays of objects polymorphically.

Note: Static type systems are often incomplete. So the goal is to make the language as expressive as possible while still making the type-checker sound.

Leave a Comment