phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Don't generalize template types

Open rvanvelzen opened this issue 3 years ago • 7 comments

A little experiment to see what happens. Psalm doesn't generalize template types either, because a @var is easy enough to write.

rvanvelzen avatar Apr 12 '22 10:04 rvanvelzen

a @var is easy enough to write

Yeah but the same argument can be used to keep the current behaviour :)

BTW Can you please tell me which items from https://github.com/phpstan/phpstan/issues/3853#issuecomment-1082351763 do you plan to work on? Once I finish the memory optimization I'm working on right now, the only thing before releasing 1.6.0 is the finished support for conditional return types, so I'd like to get that over the finish line too :) Thanks.

ondrejmirtes avatar Apr 12 '22 11:04 ondrejmirtes

a @var is easy enough to write

Yeah but the same argument can be used to keep the current behaviour :)

Definitely. Just throwing this out there :)

BTW Can you please tell me which items from phpstan/phpstan#3853 (comment) do you plan to work on? Once I finish the memory optimization I'm working on right now, the only thing before releasing 1.6.0 is the finished support for conditional return types, so I'd like to get that over the finish line too :) Thanks.

Sure. I'm planning on working on these today:

  • [ ] New rule - is the type in ConditionalTypeNode part of the function's @template type map?
  • [ ] New rule - does the parameter in ConditionalTypeForParameterNode exist?

I'm not sure how soon I'll get to any of the rest. I do realize that that doesn't help much, but I'd rather not make false promises.

rvanvelzen avatar Apr 12 '22 11:04 rvanvelzen

Yeah, this is totally fine, I can take over some of the work myself, just wanted to make sure we're synchronized (I'll let you know when I'm gonna work on some of the tasks).

ondrejmirtes avatar Apr 12 '22 12:04 ondrejmirtes

Just want to let you know that I probably won't be able to work on the conditional types this week. I was planning on doing more but life is busy as well :)

rvanvelzen avatar Apr 12 '22 14:04 rvanvelzen

No problem, I'm gonna ping you once I take over a task :)

ondrejmirtes avatar Apr 12 '22 14:04 ondrejmirtes

I'm interested in not generalizing the types, but IMHO it needs to be paired with this suggestion https://github.com/phpstan/phpstan/issues/6732#issuecomment-1062029088 to be usable. The whole thread is worth reading, but here I especially refer to the Collection<unresolved> part.

ondrejmirtes avatar May 27 '22 14:05 ondrejmirtes

Alright, I realized we can not-generalize types outside of GenericObjectType: https://github.com/phpstan/phpstan-src/pull/2818

But it's still a BC break so it's going to be bleeding edge-only for now.

Inside of GenericObjectType we're gonna need this logic https://github.com/phpstan/phpstan/issues/6732#issuecomment-1062029088

But anyway this is still going to fix a lot of issues.

ondrejmirtes avatar Dec 11 '23 14:12 ondrejmirtes