diff --git a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php index 8e1180d56..445d580a4 100644 --- a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php @@ -787,7 +787,6 @@ class CommentAnalyzer $quote_char = null; $escaped = false; - $expectation = false; for ($i = 0, $l = strlen($return_block); $i < $l; ++$i) { $char = $return_block[$i]; @@ -827,7 +826,7 @@ class CommentAnalyzer } if ($char === ':' && $last_char === ')') { - $expectation = true; + $expects_callable_return = true; $type .= $char; @@ -848,8 +847,8 @@ class CommentAnalyzer throw new DocblockParseException('Invalid string ' . $return_block); } } elseif ($char === ' ') { - if ($brackets || $expectation) { - $expectation = false; + if ($brackets) { + $expects_callable_return = false; continue; } @@ -875,8 +874,6 @@ class CommentAnalyzer continue; } - //var_dump($type); - $remaining = trim(substr($return_block, $i + 1)); if ($remaining) { @@ -886,7 +883,7 @@ class CommentAnalyzer return [$type]; } - $expectation = false; + $expects_callable_return = false; $type .= $char; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php index d240664c6..78e53ac52 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php @@ -809,9 +809,16 @@ class PropertyFetchAnalyzer $property = $class_storage->properties[$prop_name]; if ($var_id) { - $context->vars_in_scope[$var_id] = $property->type - ? clone $property->type - : Type::getMixed(); + if ($property->type) { + $context->vars_in_scope[$var_id] = ExpressionAnalyzer::fleshOutType( + $codebase, + clone $property->type, + $declaring_property_class, + $declaring_property_class + ); + } else { + $context->vars_in_scope[$var_id] = Type::getMixed(); + } $stmt->inferredType = clone $context->vars_in_scope[$var_id]; diff --git a/tests/CallableTest.php b/tests/CallableTest.php index 3fe395c16..04edda7d8 100644 --- a/tests/CallableTest.php +++ b/tests/CallableTest.php @@ -1090,7 +1090,7 @@ class CallableTest extends TestCase };', 'error_message' => 'DuplicateParam' ], - 'callableWithSpacesBadVarArg' => [ + 'callableWithSpaceAfterColonBadVarArg' => [ 'p = function (string $s, string $t): stdClass { + return new stdClass; + }; + } + }', + 'error_message' => 'InvalidPropertyAssignmentValue', + ], + 'callableWithSpaceBeforeColonBadVarArg' => [ + 'p = function (string $s, string $t): stdClass { + return new stdClass; + }; + } + }', + 'error_message' => 'InvalidPropertyAssignmentValue', + ], + 'callableWithSpacesEitherSideOfColonBadVarArg' => [ + 'p = function (string $s, string $t): stdClass { return new stdClass; diff --git a/tests/MethodCallTest.php b/tests/MethodCallTest.php index ba9455018..f329d2d53 100644 --- a/tests/MethodCallTest.php +++ b/tests/MethodCallTest.php @@ -281,6 +281,16 @@ class MethodCallTest extends TestCase } }' ], + 'varSelfCall' => [ + 'bar();', + ], ]; } diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index 84ec6140f..89057bbb5 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -1254,6 +1254,18 @@ class PropertyTypeTest extends TestCase } }', ], + 'staticVarSelf' => [ + ' 'Foo', + ] + ], ]; }