Skip to content

Commit

Permalink
Fix #1974 - prevent bad property defaults on static properties
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jul 30, 2019
1 parent c887d90 commit f718c2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,17 +637,15 @@ function ($line) {
ExpressionAnalyzer::analyze($this, $prop->default, $context);

if (isset($prop->default->inferredType)) {
if (!$stmt->isStatic()) {
if (PropertyAssignmentAnalyzer::analyzeInstance(
$this,
$prop,
$prop->name->name,
$prop->default,
$prop->default->inferredType,
$context
) === false) {
// fall through
}
if (PropertyAssignmentAnalyzer::analyzeInstance(
$this,
$prop,
$prop->name->name,
$prop->default,
$prop->default->inferredType,
$context
) === false) {
// fall through
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/PropertyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,16 @@ public function __construct() {
}',
'error_message' => 'UninitializedProperty',
],
'badStaticPropertyDefault' => [
'<?php
class TestStatic {
/**
* @var array<string, bool>
*/
public static $test = ["string-key" => 1];
}',
'error_message' => 'InvalidPropertyAssignmentValue'
],
];
}
}

0 comments on commit f718c2f

Please sign in to comment.