Skip to content

Commit

Permalink
[hack] Revise resolving field
Browse files Browse the repository at this point in the history
Summary:
This diff revises the field resolution:

1. It finds a non-abstract field from supers.
2. If not found, it finds any field including abstract one from supers.

Reviewed By: nbenton

Differential Revision: D63369252

fbshipit-source-id: 8a51e62b0f796159ddf6821b2bbcbd597ae188e9
  • Loading branch information
skcho authored and facebook-github-bot committed Sep 26, 2024
1 parent 5203af4 commit c2dc272
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
10 changes: 7 additions & 3 deletions infer/src/IR/Tenv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ let resolve_field_info tenv name fieldname =


let resolve_fieldname tenv name fieldname_str =
let find ~f =
find_map_supers ~ignore_require_extends:true tenv name ~f:(fun name str_opt ->
Option.bind str_opt ~f:(fun {Struct.fields} ->
if List.exists fields ~f then Some name else None ) )
in
let is_fld {Struct.name} = String.equal (Fieldname.get_field_name name) fieldname_str in
find_map_supers ~ignore_require_extends:true tenv name ~f:(fun name str_opt ->
Option.bind str_opt ~f:(fun {Struct.fields} ->
if List.exists fields ~f:is_fld then Some name else None ) )
let is_non_abstract_fld ({Struct.annot} as x) = is_fld x && not (Annot.Item.is_abstract annot) in
(match find ~f:is_non_abstract_fld with Some _ as fld -> fld | None -> find ~f:is_fld)
|> Option.map ~f:(fun name -> Fieldname.make name fieldname_str)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class E extends C {
}

class Tester {
public static function constant_from_interface_FP(): void {
public static function constant_from_interface_OK(): void {
D::MyC;
}

Expand Down
1 change: 0 additions & 1 deletion infer/tests/codetoanalyze/hack/pulse/issues.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
abstractconstants.hack, AbstractConstants::Tester$static.constant_from_interface_FP, 1, PULSE_UNINITIALIZED_CONST, no_bucket, ERROR, [global variable `AbstractConstants::C$static` accessed here,read to uninitialized value occurs here]
aliases.hack, Aliases::C.testAliasedShapeReturnBad, 3, PULSE_UNAWAITED_AWAITABLE, no_bucket, ERROR, [allocation part of the trace starts here,allocated by async call here,awaitable becomes unreachable here]
aliases.hack, Aliases::C.testParameterAliasOK_FP, 5, PULSE_UNAWAITED_AWAITABLE, no_bucket, ERROR, [allocation part of the trace starts here,allocated by async call here,awaitable becomes unreachable here]
arg_index_matcher.hack, Main.staticSink, 2, TAINT_ERROR, no_bucket, ERROR, [in call to `ArgIndexMatcher$static.source`,source of the taint here: value returned from `$root.Level1::taintSource` with kind `Simple`,return from call to `ArgIndexMatcher$static.source`,flows to this sink: value passed as argument `#1` to `ArgIndexMatcher$static.sink1` with kind `Simple`], source: $root.Level1::taintSource, sink: ArgIndexMatcher$static.sink1, tainted expression: $tainted
Expand Down

0 comments on commit c2dc272

Please sign in to comment.