Skip to content
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

Finish implementing support for array shapes in type checker #1382

Closed
5 tasks done
TysonAndre opened this issue Jan 22, 2018 · 0 comments
Closed
5 tasks done

Finish implementing support for array shapes in type checker #1382

TysonAndre opened this issue Jan 22, 2018 · 0 comments
Labels
enhancement This improves the quality of Phan's analysis of a codebase

Comments

@TysonAndre
Copy link
Member

TysonAndre commented Jan 22, 2018

related to #1343

class ArrayShapeType exists for array{field:T}, but I still need to do the following:

  • Stop immediately casting it to a GenericArrayType (T[])

  • When parsing union types from AST nodes, generate ArrayShapeType instead of GenericArrayType based on a heuristic. (heuristic TBD)

    E.g. if one of the key values can't be determined, then convert to GenericArrayType.

  • Add rule to check if an ArrayShapeType can cast to another ArrayShapeType, add unit tests

  • Add a rule to check if a GenericArrayType can cast to an ArrayShapeType, and vice versa

  • When normalizing union types, make sure there is at most one ArrayShapeType.
    (Haven't created a specification of what to do when there are both GenericArrayType and ArrayShapeType. One possibility is to use the GenericArrayType when keys don't match)

  • Merge two ArrayShapeType into a single ArrayShapeType when there are two branches

  • Figure out and implement a heuristic for normalizing types when recursively analyzing function calls for when quick_mode is off (one heuristic is to always cast to GenericArrayType when recursing to analyze).

  • In an assignment, If the key value is known, AssignmentVisitor should update GenericArrayType with the new key value

  • (Optional) support unset (Doesn't catch that many bugs)

  • ArrayReturnType plugin will need to be changed to properly handle array shapes.

  • UnionTypeVisitor will need to check the values of keys during array accesses. If a GenericArrayType is part of the union type, and contains that key, then the corresponding field type from the shape should be returned.


Follow-up tasks:

  • Indicate fields are optional in a shape. Modify the type checker and merging logic. Warn about fetching an optional field.

Other followup tasks:

  • Add more unit tests
  • Improve scalar casting rules. E.g. array{a:int} should not be able to cast to array{a:int, other:int}.
    A followup PR may add optional fields to array shapes
  • Test this on large projects for crashes and unexpected results
  • Reduce false positives in loops (Another PR provided ways to suppress issues for an entire file (phan-file-suppress) or to set a variable's type inline (phan-var in top level string literal))
  • Look into inferring [] as array{} in future PRs. This was disabled due to high false positives in loops
@TysonAndre TysonAndre added the enhancement This improves the quality of Phan's analysis of a codebase label Jan 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This improves the quality of Phan's analysis of a codebase
Projects
None yet
Development

No branches or pull requests

1 participant