@CompileStatic Closure Parameter Type Checking Configuration
0 reputation · 04 Dec 2024, 19:43 UTC
Goal: Ensure that when a method is annotated with @CompileStatic, the compiler validates that any closure passed as a parameter conforms to the declared parameter type, including variables captured from the enclosing scope.
Currently, Groovy treats closures as dynamically typed unless the delegate type is explicitly known, so captured variables are not checked against the closure’s expected parameter types, allowing type mismatches to surface only at runtime. This behavior persists across Groovy 3.x and 4.x and is documented as an open design decision.
Is there a compiler configuration or annotation attribute that can enforce delegate type checking for closures under @CompileStatic?
Can the type‑checking of captured variables be made part of the static analysis for @CompileStatic‑annotated methods?