-
Notifications
You must be signed in to change notification settings - Fork 476
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
Improve type specifier for identical operator #355
Conversation
Hi, thank you, but I need to orientate myself around the code a bit :) What's the significance of |
Maybe the naming is not good. And maybe it should be a method of (I believe there are plans for making dependent types work, which would certainly help here.) |
Great, I think I get your intention :) I prefer smaller PRs, I see multiple things here:
Basically we should differentiate between refactorings and fixed bugs/new features and do them separately. That workflow makes things more managable - we can see if something breaks in between rather than after one large PR. And the time inbetween PRs gives us time to ponder about the solutions and maybe think about other edge-cases and things to test. It worked really well when we implemented generics over the course of 50 small PRs :) About phpstan/phpstan#2816 - this one surprised me, I'm still a little confused about About dependent types - I see two different features here - dependence of variables certainty on other types ("if /**
* @phpstan-return array{float_test: float, foo: 'bar', lall: string, noop: int, test: int}
*/
public function data(): array
{
/** @var mixed $array */
$array = [];
return $array;
}
public function create_complex(): self {
$self = new self();
foreach($this->data() as $property => $value) {
if ($property === 'test') {
if ($self->{$property} === null) {
$self->{$property} = new \stdClass();
}
} else {
$self->{$property} = $value;
}
if ($property === 'foo') {
$self->{$property} += 1;
}
if ($property === 'foo') {
$self->{$property} .= ' ';
}
if ($property === 'lall') {
$self->{$property} += 1;
}
$tmp = 1.1;
if ($property === 'foo') {
$self->{$property} += $tmp;
}
}
return $self;
} PHPStan should know that when This is what usually needs to be done when there' a new property + constructor argument in Scope: d3e7b9c Would you be interested in exploring that? I think that if you make yourself familiar with TypeSpecifier in the current PRs, you'd be able to try doing dependent types too :) Thank you! |
Thanks for you reply! The whole Dependent types certainly sounds interesting, but also challenging. For now I'm more comfortable fixing bugs and doing small improvements. I can try to have a go at a larger feature at a later point :) I'll submit "Sort IntegerRangeType numerically" as a separate PR, it makes sense on its own. I included it here only because it made certain things easier. As for this PR here, it can be closed, I'll try to break the ideas down into smaller PRs. Sometimes I have to explore and try things before figuring out what is the best way forward. |
I get what it's supposed to mean: if ($a) {
// $a is truthy - true, object, non-empty array, etc...
} else {
// $a is falsey - false, empty array, 0, etc...
} if ($a === true) {
// $a is true
} else {
// $a can be anything else besides true
} What confuses me is when I don't care about the difference - |
Yes exactly. But at that point it might just as well be useful to do
And then let |
I can think of only two cases:
I can get away with both being hardcoded in TypeSpecifier. I can't think of a userland function/method that would behave like that, do you have any examples? :) |
OK, closing this as there will be new PRs :) (but we can continue discussing this here) |
It could also be |
Good examples :) I guess it would be nice not to have to hardcode those in TypeSpecifier. So if you make this somehow part of TypeSpecifierContext, it would be nice to prove the concept on actually implementing these examples in extensions themselves :) |
@jlherren Do you plan to restart another PR ? It would be nice to support
|
This started as a small change and became much bigger than originally intended. So I'm pushing this early as a draft to get comments and see if this is going in a useful direction or not. Or if maybe this is a too big change for pre-1.0.
The intention here was
count()
and then just improve count-related extensions)==
operator which would benefit switch-statements and fix Array size is known inside switch on count phpstan#1861However I also hit some limitations, mostly that
TypeSpecifierContext
can only tell me if something was true/truthy/false/falsey, but not what exact type something evaluated to. Hence I addedTypeSpecifier::specifyTypesInExpression()
. But it would be nice to have more precise information available in extensions as well (MethodTypeSpecifyingExtension
& co.)Let me know what you think.