Use it or Lose it: A Kotlin Static Analysis for Identifying Unused Values
Summary
Unused values found in source code may be a source of potential bugs. This is especially true for some types of values that must be eventually used by a certain set of functions. For example, an asynchronous call must be eventually awaited or canceled, otherwise it is likely a mistake. This pattern of usage is called utilization, and the types that must be utilized are the utilizable types. We present a formalization of a data-flow analysis for statically analyzing value utilization in Kotlin programs and implement a prototype of the analysis as a Kotlin compiler plugin. We extend the function signature type in Kotlin to include annotations for utilization status requirements and status-changing effects. The annotations may also be parametric in the case of higher-order functions and special types such as collections. The analysis method checks and infers the functions' utilization annotations, in addition to warning of any incomplete utilization in the functions.