Skip to content

Commit b2972b2

Browse files
committed
Tighten the cross-file function-ref check
1 parent 57f9dd1 commit b2972b2

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

analysis/reanalyze/src/DeadOptionalArgs.ml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,32 @@ let addFunctionReference ~config ~decls ~cross_file ~(locFrom : Location.t)
1313
the declaration site that should receive warnings. *)
1414
let shouldAdd =
1515
if posTo.pos_fname <> posFrom.pos_fname then
16-
match Declarations.find_opt_builder decls posTo with
17-
| Some {declKind = Value {ownsOptionalArgs; optionalArgs}} ->
18-
ownsOptionalArgs && not (OptionalArgs.isEmpty optionalArgs)
19-
| _ -> false
16+
if
17+
fileIsImplementationOf posTo.pos_fname posFrom.pos_fname
18+
|| fileIsImplementationOf posFrom.pos_fname posTo.pos_fname
19+
then
20+
match Declarations.find_opt_builder decls posTo with
21+
| Some {declKind = Value {ownsOptionalArgs; optionalArgs}} ->
22+
ownsOptionalArgs && not (OptionalArgs.isEmpty optionalArgs)
23+
| _ -> false
24+
else
25+
match
26+
( Declarations.find_opt_builder decls posFrom,
27+
Declarations.find_opt_builder decls posTo )
28+
with
29+
| ( Some
30+
{
31+
declKind =
32+
Value {ownsOptionalArgs = true; optionalArgs = sourceArgs};
33+
},
34+
Some
35+
{
36+
declKind =
37+
Value {ownsOptionalArgs = true; optionalArgs = targetArgs};
38+
} ) ->
39+
not (OptionalArgs.isEmpty sourceArgs)
40+
&& not (OptionalArgs.isEmpty targetArgs)
41+
| _ -> false
2042
else
2143
match
2244
( Declarations.find_opt_builder decls posFrom,

0 commit comments

Comments
 (0)