Open
Description
Please support to check if functions are called from the other. Let me show an example. Let me show an example.
This is the code I need to check. I need to check if I use an argument in concurrent mode.
let use_thing thing =
let%bind () = fn1 thing
and _ = fn2 thing in
return ()
let other_fn () = get_thing use_thing
And it works when this function is inside the function where get_thing
is called.
rules:
- id: concurrent-use
patterns:
- pattern-inside:
pattern-either:
- pattern: get_thing (fun $THING -> ...)
- pattern: get_thing @@ fun $THING -> ...
- pattern: let $FN_NAME $THING = ... in get_thing $FN_NAME
- pattern-either:
- pattern: let $X = ... $THING ... and $Y = ... $THING ... in ...
- pattern: let () = ... $THING ... and () = ... $THING ... in ...
- pattern: let $X = ... $THING ... and () = ... $THING ... in ...
- pattern: let () = ... $THING ... and $Y = ... $THING ... in ...
languages:
- ocaml
severity: ERROR
And this could be rewritten with the following pattern (at least the same idea works for typescript and python)
rules:
- id: concurrent-use
patterns:
- pattern:
let $F $THING = ...
...
get_thing $F
- pattern-either:
- pattern: let $X = ... $THING ... and $Y = ... $THING ... in ...
- pattern: let () = ... $THING ... and () = ... $THING ... in ...
- pattern: let $X = ... $THING ... and () = ... $THING ... in ...
- pattern: let () = ... $THING ... and $Y = ... $THING ... in ...
message: Semgrep found a match
languages:
- ocaml
severity: ERROR
But nothing is caught.
I tried this version (which is worked for typescript too):
- pattern:
let $F $THING = ...
...
let $ANOTHER_FN ... = get_thing $F
But I caught: Invalid pattern for OCaml:
Metadata
Assignees
Labels
No labels