Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Jan 6, 2025

No description provided.

@staabm
Copy link
Contributor Author

staabm commented Jan 6, 2025

//cc @VincentLanglet since its string accessory business :)

}

$accessoryTypes = [];
$valueTypeAsString = $arrayType->getIterableValueType()->toString();
Copy link
Contributor Author

@staabm staabm Jan 6, 2025

Choose a reason for hiding this comment

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

the actual change is here: we use toString as the implode function internally casts everything.

that way the string types detection also works for unions of strings and non-strings (e.g. 2|'a') and so we get more precise results

Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

Awesome

@staabm staabm force-pushed the impl2 branch 2 times, most recently from 75c4610 to 224d41d Compare January 22, 2025 13:41
@staabm staabm force-pushed the impl2 branch 3 times, most recently from 8e351b9 to 3098f46 Compare February 14, 2025 10:22
/** @param array{0: 1, 1: 'a'|'b', 3?: 'c'|'d', 4?: 'e'|'f', 5?: 'g'|'h', 6?: 'x'|'y'} $constArr */
public function constArrays6($constArr) {
assertType("string", implode('', $constArr));
assertType("literal-string&lowercase-string&non-falsy-string", implode('', $constArr));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Memo to me: Literal string is wrong here

Comment on lines +17 to +25
if (str_contains($i, 0)) {
assertType('int', $i);
}
if (str_contains($s, 0)) {
assertType('non-empty-string', $s);
}
if (str_contains($s, 1)) {
assertType('non-falsy-string', $s);
}
Copy link
Contributor Author

@staabm staabm Feb 22, 2025

Choose a reason for hiding this comment

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

these cases depends on strict-types.. are we still fine with it?

https://3v4l.org/CHDVW

@ondrejmirtes ondrejmirtes merged commit 9cd58b5 into phpstan:1.12.x Mar 9, 2025
452 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the impl2 branch March 9, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants