Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix incorrect type inference for @phpstan-assert-if-true on $this with union types #4246

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

Open
yt-catpaw wants to merge 5 commits into phpstan:2.1.x
base: 2.1.x
Choose a base branch
Loading
from yt-catpaw:bugfix/13358-assert-if-true-this
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add regression test for #11441 (assert on UnionType)
  • Loading branch information
yt-catpaw committed Aug 21, 2025
commit 6ca93cf1be92bb3c89f047ba4f6e29820b9d28e1
39 changes: 39 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-11441.php
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types=1);

namespace Bug11441;

use function PHPStan\Testing\assertType;

class Foo {
public function getParam(): ?string {
return 'foo';
}

/** @phpstan-assert !null $this->getParam() */
public function checkNotNull(): void {
if ($this->getParam() === null) {
throw new \Exception();
}
}
}

class Bar {
public function getParam(): ?int {
return 1;
}

/** @phpstan-assert !null $this->getParam() */
public function checkNotNull(): void {
if ($this->getParam() === null) {
throw new \Exception();
}
}
}

function test(Foo|Bar $obj): void {
assertType('int|string|null', $obj->getParam());

$obj->checkNotNull();

assertType('int|string', $obj->getParam());
}

AltStyle によって変換されたページ (->オリジナル) /