-
Notifications
You must be signed in to change notification settings - Fork 666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive TypeDoesNotContainType with try/finally #4366
Labels
Comments
I found these snippets: https://psalm.dev/r/903fc6c2ed<?php
class TestMe {
private function startTransaction(): void {
}
private function endTransaction(bool $commit): void {
echo $commit ? "Committing" : "Rolling back";
}
public function doWork(): void {
$this->startTransaction();
try {
// It doesn't really matter what happens here
// Or if several statements to external classes are executed
$this->workThatMayOrMayNotThrow();
// This stament is not guarenteed to execute
$success = true;
} finally {
// Whereas this one is
$this->endTransaction($success ?? false);
}
}
private function workThatMayOrMayNotThrow(): void {
}
}
|
Now fixed, but you can also rewrite that code: https://psalm.dev/r/795b8567d6 |
I found these snippets: https://psalm.dev/r/795b8567d6<?php
class TestMe {
private function startTransaction(): void {
}
private function endTransaction(bool $commit): void {
echo $commit ? "Committing" : "Rolling back";
}
public function doWork(): void {
$this->startTransaction();
$success = false;
try {
// It doesn't really matter what happens here
// Or if several statements to external classes are executed
$this->workThatMayOrMayNotThrow();
// This stament is not guarenteed to execute
$success = true;
} finally {
// Whereas this one is
$this->endTransaction($success);
}
}
private function workThatMayOrMayNotThrow(): void {
}
}
|
muglug
added a commit
that referenced
this issue
Oct 19, 2020
danog
pushed a commit
to danog/psalm
that referenced
this issue
Jan 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have some transactional code which can be simplified to the below example.
https://psalm.dev/r/903fc6c2ed
The
$success = true
at the end of the try-block is not guaranteed to execute in relation to the statement in the finally, so its value is not always true.This issue occurred in 3.17, i.e. it in 3.16 it either not checked or was not reporting this false positive.
The text was updated successfully, but these errors were encountered: