Skip to content

Native types todos #8191

@ondrejmirtes

Description

@ondrejmirtes

Feature request

1.9.x is now pretty broken for projects with treatPhpDocTypesAsCertain: false: https://github.com/phpstan/phpstan/actions/runs/3297631860/jobs/5438715560

This is because there's some work underway, but more needs to be done to fully implement it. From phpstan/phpstan-src#1802 I already merged some commits into 1.9.x: phpstan/phpstan-src@f097ca9...bf34e24

Before the rest of phpstan/phpstan-src#1802 is finished and merged, we have some work to do (in this order with no skipping):

  1. Get rid of $nativeExpressionTypes property in MutatingScope, in favour of $variableNativeTypes.
  2. Add and correctly populate $moreSpecificNativeTypes to MutatingScope. The hard question is what to do about TypeSpecifier. We probably need to call it twice in filterByTruthyValue/filterByFalseyValue/filterBySpecifiedTypes for complete and native types in order to have correct information.
  3. Some preliminary work too in order to retrieve native return type from ExtendedMethodReflection nicely, same for PropertyReflection.

And on top of phpstan/phpstan-src#1802:

  1. Get rid of phpstan/phpstan-src@8f7bbf7 (#1802) and do it in a smarter way. MutatingScope::getNativeType() should probably be implemented with a simple one-liner: return $this->promoteNativeTypes()->getType($node); and for expressions where the implementation is different do an if-else based on bool $this->nativeTypesPromoted. But most expressions will be the same.

To remind, having Scope::getNativeType() to answer truthfully for all expressions will allow us to do some cool features:

  • I'll be able to implement a rule that checks when an inline @var is always wrong, because the thing on the right side of = has a different type than what it's cast to.
  • I'll be able to eventually redesign rule levels and do a different slice across the whole rules catalogue to report useful errors earlier.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions