Merge pull request #17490 from aschackmull/java/capture-in-obinit

Java: Fix support for variable capture inside object initializers.
This commit is contained in:
Anders Schack-Mulligen
2024-09-18 09:29:01 +02:00
committed by GitHub
4 changed files with 130 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
}
}
}