Repository navigation
Share the value-vs-expected-type issue tree between arguments, returns and properties (experimental) - #14727
Conversation
…s and properties ArgumentAnalyzer::verifyType(), ReturnAnalyzer and the instance and static property assignment analyzers each walked the same tree after UnionTypeComparator::isContainedBy() (coercion from mixed, coercion, __toString cast, mismatch, null and false). It now lives in TypeMismatchReporter, with one subclass per place giving its issues. Aligning the trees fixes: - static property assignments were never checked for null and false; - true|int accepted false for properties and return values; - under strict_types, a Stringable assigned to or returned as a native string was only an ImplicitToStringCast, while PHP throws a TypeError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Under strict_types, an object only fitting a native string through __toString does not fit through a coercion of the cast string either (a non-empty-string property, a narrower return type). The rule now lives in TypeMismatchReporter for arguments, properties and returns. The code of a trait is analysed under the strict_types of the trait's file, not of the file of the class that uses it. Also adds the purity annotations of the reporters, and fixes the possibly false tempnam() assignment to a static property the new check found in PsalmEndToEndTestCase. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The scanner records the strict_types declaration in the file storage, and each function-like is analysed under the strict_types of its file: the methods of a trait, including a trait constructor analysed for property initialisations, follow the trait's file, and a file starting with a shebang keeps its declaration. ReturnTypeAnalyzer also reports InvalidReturnType when a Stringable only fits a native return type through __toString and a coercion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ethod ClassLikeAnalyzer::getMethodMutations() analyses the called method with the context of the caller, which the method now sets to the strict_types of its own file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ Performance: unchanged · Types: increased
How to read this table
✅ laravel: issues +12 −6Memory 1 772 → 1 772 MB (<0.1 %) · Wall 77.0 → 79.0 s (+2.7 %) Weighted 53 058 → 53 085 (+27, +0.05 %): L3 +3 · L6 +3
Changed in place (6); @@ 3 places @@
src/Illuminate/Database/Eloquent/Model.php:622
src/Illuminate/Database/Eloquent/Model.php:644
src/Illuminate/Database/Eloquent/Model.php:666
- PossiblyInvalidPropertyAssignmentValue: static::$lazyLoadingViolationCallback with declared type 'callable[impure]({self}, string):mixed|null' cannot be assigned type 'callable[impure]({self}, string, LazyLoadingViolationException):mixed|null'
+ InvalidPropertyAssignmentValue: static::$lazyLoadingViolationCallback with declared type 'callable[impure]({self}, string):mixed|null' cannot be assigned type 'callable[impure]({self}, string, LazyLoadingViolationException):mixed|null'
@@ 3 places PossiblyInvalidPropertyAssignmentValue @@
src/Illuminate/Validation/Rules/Email.php:80
src/Illuminate/Validation/Rules/File.php:109
src/Illuminate/Validation/Rules/Password.php:158
- …impure]|null|string' cannot be assigned type 'TGeneratedFromParam0:fn-email::defaults…
+ …impure]|null|string' cannot be assigned possibly different type 'TGeneratedFromParam0:fn-email::defaults…Added (6)
✅ symfony: issues +21 −2Memory 3 619 → 3 619 MB (<0.1 %) · Wall 263.8 → 264.9 s (+0.4 %) Weighted 100 583 → 100 640 (+57, +0.06 %): L3 +19
Changed in place (2) @@ src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php:184 PossiblyInvalidPropertyAssignmentValue @@
- …array<array-key, mixed>' cannot be assigned type 'UnitEnum|array<array-key, mixed>|null…
+ …array<array-key, mixed>' cannot be assigned possibly different type 'UnitEnum|array<array-key, mixed>|null…
@@ src/Symfony/Component/VarDumper/Caster/XmlReaderCaster.php:84 PossiblyNullPropertyAssignmentValue @@
- with non-nullable declared type 'int' cannot…
+ EnumStub::$cut with non-nullable declared type 'int' cannot…Added (19)
✅ psl: issues +0 −3Memory 618 → 618 MB (<0.1 %) · Wall 31.0 → 31.0 s (+0.0 %) Weighted 5 613 → 5 600 (−13, −0.23 %): L3 −1 · L5 −2
Removed (3)
✅ tempest: issues +25 −24Memory 898 → 898 MB (+0.0 %) · Wall 20.6 → 20.7 s (+0.4 %) Weighted 10 567 → 10 556 (−11, −0.10 %): L3 +21 · L4 −23 · L6 +3
Changed in place (9) @@ 2 places @@
packages/console/src/Components/Interactive/TextInputComponent.php:46
packages/core/src/PublishesFiles.php:267
- InvalidScalarArgument: …StaticTextBoxComponent::__construct expects null|string, but int|null|string provided
+ PossiblyInvalidArgument: …StaticTextBoxComponent::__construct expects null|string, but possibly different type int|null|string provided
@@ packages/core/src/PublishesFiles.php:246 @@
- ImplicitToStringCast: Argument 1 of AuthenticationInstaller::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of OAuthInstaller::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of CommandRepositoryInstaller::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of MakeCommandCommand::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of MakeConfigCommand::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of MakeGeneratorCommandCommand::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of MakeMiddlewareCommand::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of ConsoleInstaller::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of GeneratorCommandStub::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of MakeMigrationCommand::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of MakeModelCommand::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of MakeRequestCommand::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of MakeResponseCommand::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of SessionInstaller::detectIndent expects string, but ImmutableString|string provided with a __toString method
- ImplicitToStringCast: Argument 1 of ViteInstaller::detectIndent expects string, but ImmutableString|string provided with a __toString method
+ PossiblyInvalidArgument: Argument 1 of AuthenticationInstaller::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of OAuthInstaller::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of CommandRepositoryInstaller::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of MakeCommandCommand::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of MakeConfigCommand::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of MakeGeneratorCommandCommand::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of MakeMiddlewareCommand::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of ConsoleInstaller::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of GeneratorCommandStub::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of MakeMigrationCommand::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of MakeModelCommand::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of MakeRequestCommand::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of MakeResponseCommand::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of SessionInstaller::detectIndent expects string, but possibly different type ImmutableString|string provided
+ PossiblyInvalidArgument: Argument 1 of ViteInstaller::detectIndent expects string, but possibly different type ImmutableString|string provided
@@ 4 places @@
packages/core/src/PublishesFiles.php:248
packages/support/src/Namespace/functions.php:95
packages/support/src/Regex/functions.php:122
packages/support/src/Str/functions.php:191
- ImplicitToStringCast: Argument 1 of decode expects string, but ImmutableString|string provided with a __toString method
+ PossiblyInvalidArgument: Argument 1 of decode expects string, but possibly different type ImmutableString|string provided
@@ packages/database/src/Casters/EncryptedCaster.php:27 @@
- MixedReturnStatement: Could not infer a return type
+ InvalidReturnStatement: The inferred type 'EncryptedData|mixed|string' does not match the declared return type 'null|string' for EncryptedCaster::cast
@@ packages/support/src/Str/functions.php:645 @@
- ImplicitToStringCast: The declared return type for slice expects 'string', 'Stringable|string' provided with a __toString method
+ InvalidReturnType: The declared return type 'string' for slice is incorrect, got 'Stringable|string'Added (2)
Removed (1)
✅ guzzle-promises: issues +0 −1Memory 46 → 46 MB (+0.0 %) · Wall 1.7 → 1.8 s (+1.2 %) Weighted 436 → 433 (−3, −0.69 %): L3 −1
Removed (1)
✅ drupal: issues +10 −8Memory 4 847 → 4 847 MB (<0.1 %) · Wall 244.8 → 246.3 s (+0.6 %) Weighted 169 904 → 169 915 (+11, +0.01 %): L3 +1 · L4 −1 · L6 +2
Changed in place (8) @@ core/modules/ckeditor5/src/Controller/EntityLinkSuggestionsController.php:284 @@
- ImplicitToStringCast: The declared return type for EntityLinkSuggestionsController::computeGroup expects 'string', 'TranslatableMarkup|string' provided with a __toString method
+ InvalidReturnType: The declared return type 'string' for EntityLinkSuggestionsController::computeGroup is incorrect, got 'TranslatableMarkup|string'
@@ 2 places InvalidPropertyAssignmentValue @@
core/modules/locale/src/LocaleSource.php:109
core/modules/locale/src/LocaleSource.php:124
- with declared type 'array<array-key, LocaleFile…
+ LocaleTranslationSource::$files with declared type 'array<array-key, LocaleFile…
@@ 2 places PossiblyNullPropertyAssignmentValue @@
core/modules/locale/src/LocaleSource.php:131
core/modules/locale/src/LocaleSource.php:152
- with non-nullable declared type 'int' cannot…
+ LocaleTranslationSource::$timestamp with non-nullable declared type 'int' cannot…
@@ core/modules/views/src/Entity/View.php:528 PossiblyNullPropertyAssignmentValue @@
- with non-nullable declared type 'string…
+ ViewExecutable::$current_display with non-nullable declared type 'string…
@@ core/modules/views/src/Plugin/views/query/Sql.php:1709 PossiblyNullPropertyAssignmentValue @@
- with non-nullable declared type 'EntityInterface…
+ ResultRow::$_entity with non-nullable declared type 'EntityInterface…
@@ core/modules/views/src/Plugin/views/query/Sql.php:1712 InvalidPropertyAssignmentValue @@
- with declared type 'array<array-key, EntityInterface…
+ ResultRow::$_relationship_entities with declared type 'array<array-key, EntityInterface…Added (2)
✅ wordpress: issues +8 −0Memory 2 061 → 2 061 MB (<0.1 %) · Wall 104.3 → 104.1 s (−0.2 %) Weighted 678 558 → 678 586 (+28, <0.01 %): L3 +6 · L5 +2
Added (8)
head 33070e3 · base 86d44c1 (merge-base) · workflow run |
…ment The statements of a namespace, its functions and the closures in it were analysed before the declare statement that precedes the namespace, so outside class methods strict_types was not applied to most files. The file context now takes the declaration recorded by the scanner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Static property assignments are not checked for null and false
Psalm's own
PsalmEndToEndTestCasehad one (self::$tmpDir = tempnam(...)).Before
After
true|intaccepts false for properties and return valuesBefore
After
Under
strict_types, aStringableassigned to or returned as a nativestringis only anImplicitToStringCastPHP throws a
TypeErrorthere, as it does for arguments, which Psalm already reports asInvalidArgument.Before
After
In a namespaced file,
strict_typesonly applies to class methodsThe statements of a namespace, its functions and its closures were analysed before the
declarethat precedes the namespace.Before
After
The code of a trait is checked under the
strict_typesof the class that uses itPHP applies the
strict_typesof the file the code is written in.Before
After
Smaller alignments
?stringreportsInvalidPropertyAssignmentValue, like instance properties and arguments, instead ofPossiblyInvalidPropertyAssignmentValue(self::$nullableInt = $nullableString;), and itsPossiblyInvalidPropertyAssignmentValuemessage says "possibly different type" like the instance one.int|null|falsereports bothPossiblyNullPropertyAssignmentValueandPossiblyFalsePropertyAssignmentValue, like arguments and return statements, instead of stopping after the first; on anA|Bobject, a possibly null value no longer hides thePossiblyInvalidPropertyAssignmentValueof the other class.nullorfalseis reported even when it comes from a@psalm-ignore-nullable-return/@psalm-ignore-falsable-returnfunction, as arguments already did.ToStringTest::implicitCastInToStringloses itsdeclare(strict_types=1): under strict types, a__toString()returning an object throws aTypeError, now reported asInvalidReturnStatement/InvalidToString; the case still covers the cast without strict types.