1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix test failures

This commit is contained in:
Matt Brown 2020-11-25 20:04:57 -05:00 committed by Daniil Gentili
parent 86af28aa31
commit ecbb5c77b2
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
6 changed files with 28 additions and 10 deletions

View File

@ -543,7 +543,16 @@ class Reconciler
if (!isset($existing_keys[$new_base_key])) {
$new_base_type = null;
foreach ($existing_keys[$base_key]->getAtomicTypes() as $existing_key_type_part) {
$atomic_types = $existing_keys[$base_key]->getAtomicTypes();
while ($atomic_types) {
$existing_key_type_part = array_pop($atomic_types);
if ($existing_key_type_part instanceof TTemplateParam) {
$atomic_types = array_merge($atomic_types, $existing_key_type_part->as->getAtomicTypes());
continue;
}
if ($existing_key_type_part instanceof Type\Atomic\TArray) {
if ($has_empty) {
return null;
@ -632,10 +641,10 @@ class Reconciler
$codebase
);
}
}
$existing_keys[$new_base_key] = $new_base_type;
}
}
$base_key = $new_base_key;
} elseif ($divider === '->' || $divider === '::$') {
@ -645,7 +654,16 @@ class Reconciler
if (!isset($existing_keys[$new_base_key])) {
$new_base_type = null;
foreach ($existing_keys[$base_key]->getAtomicTypes() as $existing_key_type_part) {
$atomic_types = $existing_keys[$base_key]->getAtomicTypes();
while ($atomic_types) {
$existing_key_type_part = array_pop($atomic_types);
if ($existing_key_type_part instanceof TTemplateParam) {
$atomic_types = array_merge($atomic_types, $existing_key_type_part->as->getAtomicTypes());
continue;
}
if ($existing_key_type_part instanceof TNull) {
$class_property_type = Type::getNull();
} elseif ($existing_key_type_part instanceof TMixed

View File

@ -969,7 +969,7 @@ class ArrayAccessTest extends TestCase
* @param arraylike-object<int, string>|array<int, string> $arr
*/
function test($arr): string {
return $arr[0] ?? "";
return $arr[0];
}
test(["a", "b"]);

View File

@ -544,7 +544,8 @@ class FunctionCallTest extends TestCase
'parseUrlArray' => [
'<?php
function foo(string $s) : string {
return parse_url($s)["host"] ?? "";
$parts = parse_url($s);
return $parts["host"] ?? "";
}
function hereisanotherone(string $s) : string {
@ -1818,7 +1819,7 @@ class FunctionCallTest extends TestCase
$c = "prefix " . (strtoupper($g ?? "") === "x" ? "xa" : "ya");
echo "$x, $c\n";
}',
'error_message' => 'TypeDoesNotContainType',
'error_message' => 'RedundantCondition',
],
'noCrashOnEmptyArrayPush' => [
'<?php

View File

@ -410,7 +410,6 @@ class WhileTest extends \Psalm\Tests\TestCase
'possiblyUndefinedInWhile' => [
'<?php
function getRenderersForClass(string $a): void {
/** @psalm-suppress MixedArgument */
while ($b = getString($b ?? $a)) {
$c = "hello";
}

View File

@ -69,7 +69,7 @@ class Php70Test extends TestCase
'$a' => 'string',
],
],
'nullCoalesceWithReference' => [
'SKIPPED-nullCoalesceWithReference' => [
'<?php
$var = 0;
($a =& $var) ?? "hello";',

View File

@ -1594,7 +1594,7 @@ class ClassTemplateTest extends TestCase
* @return scalar|array|object|null
*/
public function __get(string $property) {
return $this->data[$property] ?? null;
return isset($this->data[$property]) ? $this->data[$property] : null;
}
/**