Repository navigation
Keep the witness type of ErrorType - #7294
Merged
Merged
Conversation
A path known to produce a concrete value is no longer lost when it meets an error type, so strlen() of *ERROR*+1 reports that it expects string and int is given. MixedType builds its derived types through recreate(), which ErrorType overrides to keep its reason and kind. Amp-Thread-ID: https://ampcode.com/threads/T-01a22b49-862e-7075-bc0f-c71955e86bb9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An undefined function or another error yields
ErrorType, a subclass ofMixedType. Until now it dropped the witness type, so a path known to produce a wrong value was hidden next to it:https://phpstan.org/r/7cf17f3b-a48a-4042-be7d-ac7a4e86714a
With the
checkMixedWitnessTypesbleeding edge toggle,$ais now*ERROR*+1andstrlen()reports "expects string, int given."MixedTypebuilds the types derived from it (subtract(),changeSubtractedType(),changeWitnessType(),traverse()) through a new protectedrecreate().ErrorTypeoverrides it to stay an error with its reason, with nothing subtracted.ErrorTypetakes an optional witness type in its constructor, describes it at the precise level as*ERROR*+W, compares it inequals()and removes from it insubtract().TypeCombinator::joinValues()gives witnesses to an exactErrorTypeas well as an exactMixedType; template and other subclasses still do not hold them.recreate(). Analysis output is identical with the extension on and off.Amp thread: https://ampcode.com/threads/T-01a22b49-862e-7075-bc0f-c71955e86bb9