Java: Fix support for variable capture inside object initializers.

This commit is contained in:
Anders Schack-Mulligen
2024-09-17 10:42:21 +02:00
parent add033249f
commit 20661a3c56
4 changed files with 57 additions and 4 deletions

View File

@@ -147,7 +147,14 @@ private module CaptureInput implements VariableCapture::InputSig<Location> {
}
class Callable extends J::Callable {
predicate isConstructor() { this instanceof Constructor }
predicate isConstructor() {
// InstanceInitializers are called from constructors and are equally likely
// to capture variables for the purpose of field initialization, so we treat
// them as constructors for the heuristic identification of whether to allow
// this-to-this summaries.
this instanceof Constructor or
this instanceof InstanceInitializer
}
}
}