Most of the constraint checks for an object-oriented language such as SmallJava will deal with type checking, that is, checking that expressions and statements are well-typed.
We have already seen how to perform a simple form of type checking in the Expressions DSL (Chapter 8, An Expression Language). In this chapter, we will see an advanced type checking mechanism, which includes
subtyping or type conformance: an object of class C
can be used in a context where an object of a superclass of C
is expected.
We will follow the same strategy illustrated in Chapter 8, An Expression Language: we will separate the type computation from the actual type checking. We will be able to generate the error on the sub-expression or statement that is the source of the problem. As in the previous chapter, we will implement all the type system related classes in the package typing
. This package must be exported in the MANIFEST.MF
in order to test the classes contained in this package.