mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix offset assignment creation
This commit is contained in:
parent
492269ddd4
commit
7d6ac4719f
@ -1262,7 +1262,7 @@ abstract class ClassLikeChecker implements StatementsSource
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $this_class
|
||||
* @param string|null $this_class
|
||||
* @return void
|
||||
*/
|
||||
public static function setThisClass($this_class)
|
||||
|
@ -449,6 +449,7 @@ abstract class FunctionLikeChecker implements StatementsSource
|
||||
}
|
||||
|
||||
$method_id = (string)$this->getMethodId();
|
||||
$cased_method_id = $this instanceof MethodChecker ? MethodChecker::getCasedMethodId($method_id) : $method_id;
|
||||
|
||||
if ($this instanceof MethodChecker) {
|
||||
$method_return_types = MethodChecker::getMethodReturnTypes($method_id);
|
||||
@ -493,7 +494,7 @@ abstract class FunctionLikeChecker implements StatementsSource
|
||||
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidReturnType(
|
||||
'No return type was found for method ' . MethodChecker::getCasedMethodId($method_id) .
|
||||
'No return type was found for method ' . $cased_method_id .
|
||||
' but return type \'' . $declared_return_type . '\' was expected',
|
||||
$this->getCheckedFileName(),
|
||||
$this->function->getLine()
|
||||
@ -525,7 +526,7 @@ abstract class FunctionLikeChecker implements StatementsSource
|
||||
if (IssueBuffer::accepts(
|
||||
new MixedInferredReturnType(
|
||||
'Could not verify return type \'' . $declared_return_type . '\' for ' .
|
||||
MethodChecker::getCasedMethodId($method_id),
|
||||
$cased_method_id,
|
||||
$this->getCheckedFileName(),
|
||||
$this->function->getLine()
|
||||
),
|
||||
@ -544,9 +545,8 @@ abstract class FunctionLikeChecker implements StatementsSource
|
||||
)) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidReturnType(
|
||||
'The given return type \'' . $declared_return_type . '\' for ' .
|
||||
MethodChecker::getCasedMethodId($method_id) . ' is incorrect, got \'' .
|
||||
$inferred_return_type . '\'',
|
||||
'The given return type \'' . $declared_return_type . '\' for ' . $cased_method_id .
|
||||
' is incorrect, got \'' . $inferred_return_type . '\'',
|
||||
$this->getCheckedFileName(),
|
||||
$this->function->getLine()
|
||||
),
|
||||
|
@ -848,6 +848,10 @@ class FetchChecker
|
||||
$array_type = $atomic_array->type_params[1];
|
||||
} else {
|
||||
$atomic_array->type_params[0] = $key_type;
|
||||
|
||||
if ($nesting === 0 && $keyed_assignment_type) {
|
||||
$atomic_array->type_params[1] = $keyed_assignment_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +157,8 @@ class StatementsChecker
|
||||
}
|
||||
|
||||
/*
|
||||
if (isset($context->vars_in_scope['$this'])) {
|
||||
var_dump($stmt->getLine() . ' ' . $context->vars_in_scope['$this']);
|
||||
if (isset($context->vars_in_scope['$columns'])) {
|
||||
var_dump($stmt->getLine() . ' ' . $context->vars_in_scope['$columns']);
|
||||
}
|
||||
*/
|
||||
|
||||
@ -222,7 +222,7 @@ class StatementsChecker
|
||||
}
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\Function_) {
|
||||
$function_context = new Context($this->file_name, $context->self);
|
||||
$function_checkers[$stmt->name]->check($function_context);
|
||||
$function_checkers[$stmt->name]->check($function_context, $context);
|
||||
} elseif ($stmt instanceof PhpParser\Node\Expr) {
|
||||
ExpressionChecker::check($this, $stmt, $context);
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\InlineHTML) {
|
||||
|
@ -396,4 +396,22 @@ class ArrayAssignmentTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('string', (string)$context->vars_in_scope['$b']);
|
||||
$this->assertEquals('string', (string)$context->vars_in_scope['$e']);
|
||||
}
|
||||
|
||||
public function testVariableKeyArrayCreate()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
$a = [];
|
||||
$b = "boop";
|
||||
$a[$b][] = "bam";
|
||||
|
||||
$c = [];
|
||||
$c[$b][$b][] = "bam";
|
||||
');
|
||||
|
||||
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->check(true, true, $context);
|
||||
$this->assertEquals('array<string,array<int,string>>', (string) $context->vars_in_scope['$a']);
|
||||
$this->assertEquals('array<string,array<string,array<int,string>>>', (string) $context->vars_in_scope['$c']);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user