From 45a94af0151d081ac512242549d3eb9c2141e51e Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 12 Jun 2018 11:19:35 -0400 Subject: [PATCH] Fix #814 - remove literal types when removing base key --- src/Psalm/Type/Union.php | 15 +++++++++++++++ tests/ValueTest.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index dbf217c4b..d07a0f5af 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -399,6 +399,21 @@ class Union $this->id = null; return true; + } elseif ($type_string === 'string' && $this->literal_string_types) { + foreach ($this->literal_string_types as $literal_key => $_) { + unset($this->types[$literal_key]); + } + $this->literal_string_types = []; + } elseif ($type_string === 'int' && $this->literal_int_types) { + foreach ($this->literal_int_types as $literal_key => $_) { + unset($this->types[$literal_key]); + } + $this->literal_int_types = []; + } elseif ($type_string === 'float' && $this->literal_float_types) { + foreach ($this->literal_float_types as $literal_key => $_) { + unset($this->types[$literal_key]); + } + $this->literal_float_types = []; } return false; diff --git a/tests/ValueTest.php b/tests/ValueTest.php index 281a9e78f..933b8c11b 100644 --- a/tests/ValueTest.php +++ b/tests/ValueTest.php @@ -369,6 +369,42 @@ class ValueTest extends TestCase } }', ], + 'removeLiteralStringForNotIsString' => [ + ' [ + ' [ + '