Skip to content

Tester\Assert::fail() is treated as early-terminating - #2

Open
xificurk wants to merge 1 commit into
nette:masterfrom
xificurk:tester-assert-fail
Open

xificurk wants to merge 1 commit into
nette:masterfrom
xificurk:tester-assert-fail

Conversation

@xificurk

@xificurk xificurk commented Nov 1, 2026

Copy link
Copy Markdown
  • new feature
  • BC break (likely) no

Tester\Assert::fail() is now listed in earlyTerminatingMethodCalls, so code after it is treated as unreachable and type narrowing holds:

if ($val === null) {
    Assert::fail('must not be null');
}
// $val is int here, was int|null

fail() can't be declared never natively: it returns void because an Assert::$onFailure handler may swallow the failure and continue. Every type-narrowing assertion already assumes that a failed assertion ends the test, so fail() follows the same convention.

fail() returns void because an Assert::$onFailure handler may swallow
the failure, but like every other assertion it is meant to end the test.

Co-Authored-By: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant