-
Notifications
You must be signed in to change notification settings - Fork 518
Fixed HasOffsetValueType
accessory missing main-type
#4162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
staabm
wants to merge
15
commits into
phpstan:2.1.x
Choose a base branch
from
staabm:bug13270_mixed
base: 2.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
af53509
Fixed HasOffsetValueType accessory missing main-type
staabm 17eff3f
address feedback
staabm a087a49
fix php7 build
staabm e732d4a
assert more
staabm ebd5ab0
narrow types in foreach expr
staabm 520924e
Delete .phpunit.cache/test-results
staabm f4850c1
Delete bug-13310.php
staabm 96ea1d3
Delete test.php
staabm fe873d6
fix php 7.4
staabm f40c14a
Added regression test
staabm f47056b
improve naming
staabm da08c77
simplify
staabm 3e6426c
Discard changes to tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php
staabm 93fbacb
Delete tests/PHPStan/Rules/Functions/data/bug-7076.php
staabm a641c00
fix php7.4 build
staabm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php // lint >= 8.0 | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Bug13270a; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
final class HelloWorld | ||
{ | ||
/** | ||
* @param array<mixed> $data | ||
*/ | ||
public function test(array $data): void | ||
{ | ||
foreach($data as $k => $v) { | ||
assertType('non-empty-array<mixed>', $data); | ||
$data[$k]['a'] = true; | ||
assertType("non-empty-array<(non-empty-array&hasOffsetValue('a', true))|(ArrayAccess&hasOffsetValue('a', true))>", $data); | ||
foreach($data[$k] as $val) { | ||
} | ||
} | ||
} | ||
|
||
public function doFoo( | ||
mixed $mixed, | ||
mixed $mixed2, | ||
mixed $mixed3, | ||
mixed $mixed4, | ||
int $i, | ||
int $i2, | ||
string|int $stringOrInt | ||
): void | ||
{ | ||
$mixed[$i]['a'] = true; | ||
assertType('mixed', $mixed); | ||
|
||
$mixed2[$stringOrInt]['a'] = true; | ||
assertType('mixed', $mixed2); | ||
|
||
$mixed3[$i][$stringOrInt] = true; | ||
assertType('mixed', $mixed3); | ||
|
||
$mixed4['a'][$stringOrInt] = true; | ||
assertType('mixed', $mixed4); | ||
|
||
$null = null; | ||
$null[$i]['a'] = true; | ||
assertType('non-empty-array<int, array{a: true}>', $null); | ||
|
||
$i2['a'] = true; | ||
assertType('*ERROR*', $i2); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Bug13270b; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Test | ||
{ | ||
/** | ||
* @param mixed[] $data | ||
* @return mixed[] | ||
*/ | ||
public function parseData(array $data): array | ||
{ | ||
if (isset($data['price'])) { | ||
assertType('mixed~null', $data['price']); | ||
if (!array_key_exists('priceWithVat', $data['price'])) { | ||
$data['price']['priceWithVat'] = null; | ||
} | ||
assertType("(non-empty-array&hasOffsetValue('priceWithVat', mixed))|(ArrayAccess&hasOffsetValue('priceWithVat', null))", $data['price']); | ||
if (!array_key_exists('priceWithoutVat', $data['price'])) { | ||
$data['price']['priceWithoutVat'] = null; | ||
} | ||
} | ||
return $data; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php // lint >= 8.0 | ||
|
||
namespace Bug13312; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function fooArr(array $arr): void { | ||
assertType('array', $arr); | ||
foreach ($arr as $v) { | ||
assertType('non-empty-array', $arr); | ||
} | ||
assertType('array', $arr); | ||
|
||
for ($i = 0; $i < count($arr); ++$i) { | ||
assertType('non-empty-array', $arr); | ||
} | ||
assertType('array', $arr); | ||
} | ||
|
||
/** @param list<mixed> $arr */ | ||
function foo(array $arr): void { | ||
assertType('list<mixed>', $arr); | ||
foreach ($arr as $v) { | ||
assertType('non-empty-list<mixed>', $arr); | ||
} | ||
assertType('list<mixed>', $arr); | ||
|
||
for ($i = 0; $i < count($arr); ++$i) { | ||
assertType('non-empty-list<mixed>', $arr); | ||
} | ||
assertType('list<mixed>', $arr); | ||
} | ||
|
||
|
||
function fooBar(mixed $mixed): void { | ||
assertType('mixed', $mixed); | ||
foreach ($mixed as $v) { | ||
assertType('iterable', $mixed); // could be non-empty-array|Traversable | ||
} | ||
assertType('mixed', $mixed); | ||
|
||
foreach ($mixed as $v) {} | ||
|
||
assertType('mixed', $mixed); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.