Pattern 22 | Enforcing Static Type Safety |
Purpose
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.
Discussion
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.
-
if conditionals must evaluate to a boolean
Get Language Implementation Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.