Skip to content

Commit e3a7aa7

Browse files
authored
Merge branch refs/heads/1.11.x into 1.12.x
2 parents e347531 + c28c936 commit e3a7aa7

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

Diff for: src/Type/Accessory/AccessoryLiteralStringType.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ public function getOffsetValueType(Type $offsetType): Type
153153

154154
public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
155155
{
156-
return $this;
156+
if ($valueType->isLiteralString()->yes()) {
157+
return $this;
158+
}
159+
160+
return new StringType();
157161
}
158162

159163
public function setExistingOffsetValueType(Type $offsetType, Type $valueType): Type

Diff for: src/Type/Accessory/AccessoryNonFalsyStringType.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ public function getOffsetValueType(Type $offsetType): Type
155155

156156
public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
157157
{
158-
return $this;
158+
if ($valueType->isNonFalsyString()->yes()) {
159+
return $this;
160+
}
161+
162+
return new StringType();
159163
}
160164

161165
public function setExistingOffsetValueType(Type $offsetType, Type $valueType): Type

Diff for: tests/PHPStan/Analyser/nsrt/bug-3981.php

+29
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@ public function doFoo(string $s, string $nonEmptyString): void
2020
assertType('non-empty-string', $nonEmptyString[0]);
2121
assertType('non-empty-string', $nonEmptyString[1]);
2222
assertType('non-empty-string', $s[0]);
23+
24+
assertType('string', $s);
25+
26+
$s[0] = '1';
27+
assertType('non-empty-string', $s);
28+
}
29+
30+
/**
31+
* @param literal-string $literalString
32+
*/
33+
public function doBar(string $literalString, string $generalString): void
34+
{
35+
$literalString[0] = 'a';
36+
assertType('literal-string&non-empty-string', $literalString);
37+
38+
$literalString[1] = $generalString;
39+
assertType('non-empty-string', $literalString);
40+
}
41+
42+
/**
43+
* @param non-falsy-string $nonFalsyString
44+
*/
45+
public function doBaz(string $nonFalsyString, string $generalString): void
46+
{
47+
$nonFalsyString[0] = 'a';
48+
assertType('non-falsy-string', $nonFalsyString);
49+
50+
$nonFalsyString[1] = $generalString;
51+
assertType('non-empty-string', $nonFalsyString);
2352
}
2453

2554
}

0 commit comments

Comments
 (0)