Abstract

We present a simple, practical, and expressive relational nullable type system. A relational nullable type system captures whether an expression may evaluate to null based on its type, but also based on the type of other related expressions. The type system extends the Hindley-Milner type system with Boolean constraints, supports parametric polymorphism, and preserves principal types modulo Boolean equivalence. We show how to support full Hindley-Milner style type inference with an extension of Algorithm W. We conduct a preliminary study of open source projects showing that there is a need for relational nullable type systems across a wide range of programming languages. The most important findings from the study are: (i) programmers use programming patterns where the nullability of one expression depends on the nullability of other related expressions, (ii) such invariants are commonly enforced with run-time exceptions, and (iii) reasoning about these programming patterns requires not only knowledge of when an expression may evaluate to null, but also when it may evaluate to a non-null value. We incorporate these observations in the design of the proposed relational nullable type system.

Highlights

  • Null Ð infamously dubbed the łBillion Dollar Mistakež by its inventor Sir Tony Hoare Ð is a special value that is an inhabitant of every type

  • The most important findings from the study are: (i) programmers use programming patterns where the nullability of one expression depends on the nullability of other related expressions, (ii) such invariants are commonly enforced with run-time exceptions, and (iii) reasoning about these programming patterns requires knowledge of when an expression may evaluate to null, and when it may evaluate to a non-null value

  • We present a declarative type system for the calculus based on Hindley-Milner extended with Boolean constraints and we show how to perform principal type inference using an extension of Algorithm W

Read more

Summary

Introduction

Null Ð infamously dubbed the łBillion Dollar Mistakež by its inventor Sir Tony Hoare Ð is a special value that is an inhabitant of every type. Null is dangerous because any attempt to use it as an ordinary value, e.g. by dereference or invocation, triggers the dreaded NullPointerException crashing the program or, even worse, leading to undefined behavior, depending on the semantics of the programming language. A nullable type system prevents such crashes or undefined behavior by tracking, for every expression, whether it may evaluate to null [Banerjee et al 2019; Fähndrich and Xia 2007; Nieto et al 2020b; Summers and Müller 2011]. If an expression is nullable the programmer must explicitly check for null before the result of the expression can be used. On the other hand, an expression is non-nullable the type system guarantees that the expression cannot evaluate to null at run-time. The programmer does not have to check for null

Objectives
Methods
Results
Conclusion
Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call