Skip to content

Commit 8fc2f23

Browse files
committed
Fix
1 parent 54f67c5 commit 8fc2f23

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Type/Constant/ConstantStringType.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Type\Constant;
44

5-
use Error;
65
use Nette\Utils\RegexpException;
76
use Nette\Utils\Strings;
87
use PhpParser\Node\Name;
@@ -291,12 +290,15 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $uni
291290
&& $valueStringType instanceof ConstantStringType
292291
) {
293292
$value = $this->value;
294-
295-
try {
296-
$value[$offsetType->getValue()] = $valueStringType->getValue();
297-
} catch (Error) {
293+
$offsetValue = $offsetType->getValue();
294+
if ($offsetValue < 0) {
295+
return new ErrorType();
296+
}
297+
$stringValue = $valueStringType->getValue();
298+
if (strlen($stringValue) !== 1) {
298299
return new ErrorType();
299300
}
301+
$value[$offsetValue] = $stringValue;
300302

301303
return new self($value);
302304
}

0 commit comments

Comments
 (0)