Skip to content
Permalink
Browse files

Fix #1974 - prevent bad property defaults on static properties

  • Loading branch information...
muglug committed Jul 30, 2019
1 parent c887d90 commit f718c2fca166f61bbb23549609790b19b98fd14f
Showing with 19 additions and 11 deletions.
  1. +9 −11 src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
  2. +10 −0 tests/PropertyTypeTest.php
@@ -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
}
}
}
@@ -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.
You can’t perform that action at this time.