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

seal the result of two sealed KeyedArrays

This commit is contained in:
orklah 2021-08-09 20:43:17 +02:00
parent cccfe7582d
commit e688781383
2 changed files with 26 additions and 2 deletions

View File

@ -544,13 +544,16 @@ class NonDivArithmeticOpAnalyzer
}
}
$result_type_member = new Type\Union([new TKeyedArray($properties)]);
$new_keyed_array = new TKeyedArray($properties);
$new_keyed_array->sealed = $left_type_part->sealed && $right_type_part->sealed;
$result_type_member = new Type\Union([$new_keyed_array]);
} else {
$result_type_member = TypeCombiner::combine(
[$left_type_part, $right_type_part],
$codebase,
true
);
}
if (!$result_type) {

View File

@ -1545,7 +1545,8 @@ class ArrayAssignmentTest extends TestCase
}'
],
'ArrayCreateTemplateArrayKey' => [
'/**
'<?php
/**
* @template K of array-key
* @param K $key
*/
@ -1610,6 +1611,26 @@ class ArrayAssignmentTest extends TestCase
}
}',
],
'AddTwoSealedArrays' => [
'<?php
final class Token
{
public const ONE = [
16 => 16,
];
public const TWO = [
17 => 17,
];
public const THREE = [
18 => 18,
];
}
$_a = Token::ONE + Token::TWO + Token::THREE;
',
'assertions' => ['$_a' => 'array{16: 16, 17: 17, 18: 18}']
],
];
}