-
Notifications
You must be signed in to change notification settings - Fork 665
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
Fix type of property-get with coalesce #11152
base: 5.x
Are you sure you want to change the base?
Conversation
if (isset($context->vars_in_scope['$this'])) { | ||
InstancePropertyFetchAnalyzer::analyze( | ||
$statements_analyzer, | ||
$isset_var, | ||
$context, | ||
); | ||
} | ||
if (!isset($context->vars_in_scope[$var_id])) { | ||
$context->vars_in_scope[$var_id] = Type::getMixed(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value of InstancePropertyFetchAnalyzer::analyze is discarded, not sure if/how it needs to be handled.
@@ -30,7 +31,16 @@ public static function analyze( | |||
$var_id = '$this->' . $isset_var->name->name; | |||
|
|||
if (!isset($context->vars_in_scope[$var_id])) { | |||
$context->vars_in_scope[$var_id] = Type::getMixed(); | |||
if (isset($context->vars_in_scope['$this'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is necessary to keep this test passing:
psalm/tests/TypeReconciliation/ScopeTest.php
Lines 165 to 174 in 3f52ded
'suppressInvalidThis' => [ | |
'code' => '<?php | |
/** @psalm-suppress InvalidScope */ | |
if (!isset($this->value)) { | |
$this->value = ["x", "y"]; | |
echo count($this->value) - 2; | |
}', | |
'assertions' => [], | |
'ignored_issues' => ['MixedPropertyAssignment', 'MixedArgument'], | |
], |
This checks if this is inside an object context and dynamic property access is possible.
Fixes #11151
If the property was not already known inside the IssetAnalyzer::analyze function, it was added as mixed to the context.
This adds a check for dynamic properties.