Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-9004.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Bug9004;

use function PHPStan\Testing\assertType;

$test = [];
foreach (['a', 'b', 'c'] as $letter) {
if (rand(0, 1) == 0) {
assertType("array{}|array{hi: 'hello'}|array{hi: array{0: 42, 1?: 42}}", $test);
if (isset($test['hi']) && is_string($test['hi'])) {
continue;
}
$test['hi'][] = 42;
} else {
$test['hi'] = 'hello';
}
}
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,15 @@ public function testAppendToArrayWithPhpIntMaxKey(): void
]);
}

public function testBug9004(): void
{
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-9004.php'], [
[
'Cannot assign new offset to list<int>|string.',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second reading, This error should not be reported thought

I feel like the issue might not be solved since we just trade an error for another @staabm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reading ondrejs comment, I got the impression it is a expected error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the opposite, since he say "it shouldn't report: "Cannot assign new offset to array<int, int>|string.""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open a dedicated issue to run the bot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reading it again - you are right

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

14,
],
]);
}

}
Loading