You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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:
Other followup tasks:
array{a:int}
should not be able to cast toarray{a:int, other:int}
.A followup PR may add optional fields to array shapes
[]
asarray{}
in future PRs. This was disabled due to high false positives in loopsThe text was updated successfully, but these errors were encountered: