Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Sep 28, 2025

Need #4386
Need #4387

@staabm
Copy link
Contributor

staabm commented Sep 29, 2025

Did you double check the issue bot results are intentional?

@VincentLanglet
Copy link
Contributor Author

Did you double check the issue bot results are intentional?

Yes, the issue bot is misleading,
Currently there is already 23 errors on PHP 7.4 issue https://phpstan.org/r/f0a1d9d3-a829-4b6f-b21f-38295454a458 cause "mixed" is not a known type. I "add" 3 errors "Offset mixed does not exists" for the same reason.
But the snippet is not changed in PHP 8+

@VincentLanglet VincentLanglet force-pushed the nonExistentOffset branch 3 times, most recently from a77fd4b to b2a5e81 Compare October 2, 2025 12:30
"ignorable": true
},
{
"message": "Offset DateTimeImmutable does not exist on array.",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As expected, I reduce the duplicates from #4387

@VincentLanglet VincentLanglet marked this pull request as ready for review October 2, 2025 12:44
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit 89ee746 into phpstan:2.1.x Oct 2, 2025
542 of 550 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

$validArrayDimType = TypeCombinator::intersect(AllowedArrayKeysTypes::getType(), $dimType);

foreach ($flattenedTypes as $innerType) {
$dimTypeToCheck = $innerType->isArray()->yes() ? $validArrayDimType : $dimType;
Copy link
Contributor Author

@VincentLanglet VincentLanglet Oct 2, 2025

Choose a reason for hiding this comment

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

This only apply to array because we just have InvalidKeyInArrayDimFetchRule.

But you considered maybe extending the rule to String.

I wonder if in another PR we should create something like

  • isOffsetValueTypeLegal(Type $offsetType, PHPVersion $phpVersion) (with maybe a strict param...)
  • ArrayType::isOffsetValueTypeLegal rely on AllowedArrayKeysTypes::getType`
  • We use isOffsetValueTypeLegal in InvalidKeyInArrayDimFetchRule
  • And we use it here to filter the offsetDim

Dunno... this topic does not seems to be easy ^^'

@ondrejmirtes
Copy link
Member

This PR causes this error to be reported on level < 9 which is a bug: https://phpstan.org/r/bbec48eb-1e0b-4c45-830a-46792cdfba3f

@ondrejmirtes
Copy link
Member

Reverting as I want to do a release.

@VincentLanglet
Copy link
Contributor Author

This PR causes this error to be reported on level < 9 which is a bug: phpstan.org/r/bbec48eb-1e0b-4c45-830a-46792cdfba3f

Indeed, MixedType shouldn't be intersected because it will transform it into an uniontype and lower the error level.
Fixed in #4398

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants