Abstract:
Programmers often insert assertions in their code to be optionally checked at runtime,
at least during the debugging phase. In the context of design by contracts, these assertions
would better be given as a precondition of the method/procedure which can detect that
a caller has violated the procedure's contract in a way which definitely leads to an assertion violation (e.g. for separate static analysis). We define precisely and formally the contract inference problem from intermittent assertions inserted in the code by the programmer. Our definition excludes no good run even when a non-deterministic choice (e.g. an interactive input) could lead to a bad one (so this is not the weakest precondition since a terminating successful execution is not guaranteed). We then introduce new abstract interpretation-based methods to automatically infer both the static contract precondition of a method/procedure and the code to check it at runtime on scalar and collection variables.