Skip to content

Commit

Permalink
Fix AccessoryNonFalsyStringType::setOffsetValueType()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 14, 2024
1 parent 93c5226 commit c28c936
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Type/Accessory/AccessoryNonFalsyStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ public function getOffsetValueType(Type $offsetType): Type

public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
{
return $this;
if ($valueType->isNonFalsyString()->yes()) {
return $this;
}

return new StringType();
}

public function setExistingOffsetValueType(Type $offsetType, Type $valueType): Type
Expand Down
13 changes: 12 additions & 1 deletion tests/PHPStan/Analyser/nsrt/bug-3981.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function doFoo(string $s, string $nonEmptyString): void

/**
* @param literal-string $literalString
* @param literal-string $anotherLiteralString
*/
public function doBar(string $literalString, string $generalString): void
{
Expand All @@ -40,4 +39,16 @@ public function doBar(string $literalString, string $generalString): void
assertType('non-empty-string', $literalString);
}

/**
* @param non-falsy-string $nonFalsyString
*/
public function doBaz(string $nonFalsyString, string $generalString): void
{
$nonFalsyString[0] = 'a';
assertType('non-falsy-string', $nonFalsyString);

$nonFalsyString[1] = $generalString;
assertType('non-empty-string', $nonFalsyString);
}

}

0 comments on commit c28c936

Please sign in to comment.