Pattern 22Enforcing Static Type Safety


This pattern statically detects incompatible types in expressions and statements.

You can extrapolate from this pattern everything you’d need to build a type safety checker for any statically typed language with explicit declarations like C. Tools such as compilers that translate or otherwise analyze a statically typed language need this pattern.


A static type checker adds type compatibility checks to Pattern 21, Automatic Type Promotion (which is, in turn, based upon Pattern 20, Computing Static Expression Types). We’re going to enforce the type compatibility checks described in Figure 23, The type compatibility rules Cymbol enforces.

  1. if conditionals must evaluate to a boolean

Get Language Implementation Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.