Skip to content

Do not analyse stub files with errors when the result cache is restored - #6891

Merged
ondrejmirtes merged 1 commit into
2.3.xfrom
result-cache-stub-files-with-errors
Oct 31, 2026
Merged

ondrejmirtes merged 1 commit into
2.3.xfrom
result-cache-stub-files-with-errors

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

The errors that the stub validation reports are kept in the result cache under the stub file, and restored with it. When a new analysed file appears, or the symbols of a file that is not analysed change, every file with errors is re-analysed — and the stub file was one of them. It was then analysed like a project file, so the rules for analysed files reported errors in it, such as a missing return statement in each method that has a return type and no body. Those errors were then cached too.

It needs a stub file outside the vendor directory with an error from the stub validation, a cache from a full analysis, and a new file:

// stubs/test.stub
class Foo
{
	public function doFoo($a): string
	{
	}
}
  1. Full analysis: Method Foo::doFoo() has parameter $a with no type specified.
  2. Add a file to the analysed paths, then run again: the same error, plus Method Foo::doFoo() should return string but return statement is missing.

Found with TwigStan, which creates new compiled templates on most runs: after an update, its own CoreExtension.stub, installed from a path repository, reported 145 errors in a warm run and none in a cold one.

The stub files are now skipped when the files with errors are re-analysed. They keep their errors from the stub validation, which runs again when a stub file changes, because that discards the result cache.

The e2e test result-cache-stub-files-errors fails without the change.

The errors of the stub validation are kept in the result cache under the
stub file. When a new file appeared, every file with errors was re-analysed,
the stub file too, so the rules for analysed files reported errors in it,
such as a missing return statement in each method without a body.

Amp-Thread-ID: https://ampcode.com/threads/T-01a18c38-cedb-76c4-8a09-c5e85fea5b60
@ondrejmirtes
ondrejmirtes merged commit 091c5a7 into 2.3.x Oct 31, 2026
587 of 588 checks passed
@ondrejmirtes
ondrejmirtes deleted the result-cache-stub-files-with-errors branch October 31, 2026 07:21
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