Scala Capture Checking: The Tech Behind a Failed Talk
This article recounts the author's failed presentation on capture checking at Scala Days 2025 and the subsequent deep dive into the technology. Capture checking aims to solve the problem of values escaping their intended scope, such as premature closure of resources in try-with-resource patterns. Scala implements capture checking by introducing 'capture sets', a type system feature that allows marking a type and all values it captures. The article details capture sets, subtyping, syntactic sugar, and the mechanisms for capturing functions and classes, exploring capture set behavior in type parameters. Ultimately, the author argues that while capture checking involves many details, it's a largely invisible feature for most developers, improving Scala's safety and enabling wider capabilities usage.
Read more