Skip to content

Conversation

rajyan
Copy link
Contributor

@rajyan rajyan commented Oct 30, 2022

Refactoring mentioned in
#1919 (comment)
Now all types are merged with expressionTypes!

Now we are ready to start
phpstan/phpstan#8191

@rajyan rajyan force-pushed the merge-constant-types branch from 2d99e27 to a0a6a42 Compare October 30, 2022 11:58
@rajyan
Copy link
Contributor Author

rajyan commented Oct 30, 2022

I don't have enough context for test change 98a960b

@ondrejmirtes
Copy link
Member

I think the next step is figure out what to do with TypeSpecifier and filterBySpecifiedTypes so that it also fills nativeExpressionTypes correctly.

Also - I'd love to see us to get rid of $conditionalExpressions and to have some new LateResolvableType as part of $expressionTypes too.

@rajyan
Copy link
Contributor Author

rajyan commented Oct 30, 2022

I'm excited for the next steps!

@rajyan
Copy link
Contributor Author

rajyan commented Oct 30, 2022

I noticed that ScopeFactory::create seems covered by BC break...? The failing test of larastan was cause by this...

@ondrejmirtes
Copy link
Member

Also, I'm reviewing MutatingScope.php on top of this PR and there are some inconsistencies in handling $this->expressionTypes and $this->nativeExpressionTypes. For example in:

  • specifyExpressionType (lines 3457, 3458) - one is assigned, another one is unset
  • invalidateExpression - it goes over keys in $this->expressionTypes, does some logic and then tries to unset the keys on both expressionTypes and nativeExpressionTypes. I'd rather see the same foreach run twice separately.
  • Same in invalidateMethodsOnExpression
  • Sometimes large blocks of logic are unnecesarily duplicated for expressionTypes and nativeExpressionTypes, it'd be nicer to have some new private methods instead. (for example in processAlwaysIterableForeachScopeWithoutPollute)
  • Private method addMoreSpecificTypes only handles expressionTypes and doesn't do anything with nativeExpressionTypes. It's only called from specifyExpressionType but I feel like something should be done here, especially when the method has Type $nativeType in the parameters.
  • processClosureScope - same $variableType is used for both expressionTypes and nativeExpressionTypes which is certainly wrong.

I think these should also be cleaned up frist :)

@rajyan
Copy link
Contributor Author

rajyan commented Oct 30, 2022

Thank you for the signposts.
Lot more fun things to do:)

@rajyan rajyan marked this pull request as ready for review October 30, 2022 12:24
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@rajyan
Copy link
Contributor Author

rajyan commented Oct 30, 2022

Sorry
https://github.com/phpstan/phpstan-src/actions/runs/3355392157/jobs/5559633971
this test failure should be investigated

@rajyan rajyan marked this pull request as draft October 30, 2022 12:26
@rajyan
Copy link
Contributor Author

rajyan commented Oct 30, 2022

and webmozart-assert test too
https://github.com/phpstan/phpstan-src/actions/runs/3355392157/jobs/5559637937

not sure why Assert::notEq(true, true) is failing while Assert::eq(true, true) is working.

@ondrejmirtes
Copy link
Member

I have some idea - these language constants should stay the same, true is always true, but your refactoring probably made it not treated specially and thus from that point true is NeverType or something...

@rajyan rajyan force-pushed the merge-constant-types branch 2 times, most recently from 6523bd7 to 1e49c11 Compare October 30, 2022 12:52
@rajyan
Copy link
Contributor Author

rajyan commented Oct 30, 2022

Understood
#1938 (comment)

ConstFetch should be kept everywhere, even out of class

@rajyan rajyan marked this pull request as ready for review October 30, 2022 13:29
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Oct 30, 2022

Another todo: $this in enterClosureBind and restoreOriginalScopeAfterClosureBind and enterClosureCall :)

@ondrejmirtes
Copy link
Member

There are still some test failures :)

@ondrejmirtes
Copy link
Member

About the BC break in ScopeFactory - yeah, it's annoying we can't change it as easily as this, I'm trying if Larastan can call it with less arguments here: larastan/larastan#1430

@ondrejmirtes
Copy link
Member

My plan to address ScopeFactory is:

  • Public ScopeFactory will have just one parameter in create() - ScopeContext
  • MutatingScope will use new InternalScopeFactory with create() method parameters as they are now in ScopeFactory

@ondrejmirtes
Copy link
Member

I need this for an optimization so I'm gonna merge it now :) Thank you very much!

@ondrejmirtes ondrejmirtes merged commit 285b49f into phpstan:1.9.x Oct 30, 2022
@herndlm
Copy link
Contributor

herndlm commented Oct 30, 2022

Sitting back and watching the step-by-step cleanups is fun. This looks like another good one 😊

@ondrejmirtes
Copy link
Member

Would be nice to fix this one because it's now worse than before :) phpstan/phpstan#8034

@rajyan
Copy link
Contributor Author

rajyan commented Oct 30, 2022

There are still some test failures :)

Sorry for it. I had to go sleep:)
Thank you for completing it.

@rajyan rajyan deleted the merge-constant-types branch October 30, 2022 22:42
@rajyan
Copy link
Contributor Author

rajyan commented Oct 31, 2022

Would be nice to fix this one because it's now worse than before :) phpstan/phpstan#8034

Steps to fix

@ondrejmirtes
Copy link
Member

This Composer failure is weird: https://github.com/phpstan/phpstan/actions/runs/3359189577/jobs/5566968926

 ------ ---------------------------------------------------------------------- 
  Line   tests/Composer/Test/Package/Archiver/ZipArchiverTest.php              
 ------ ---------------------------------------------------------------------- 
  91     Strict comparison using === between string|null and null will always  
         evaluate to false.                                                    
 ------ ---------------------------------------------------------------------- 

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