rescript-association/reanalyze

Local module alias is not followed for exception analysis

TheSpyder opened this issue ยท 5 comments

I have some code that shadows an exception-throwing module with a safer one, but reanalyze still flags the code as throwing an exception. This is a contrived example, but it does replicate the issue:

module Array = Belt.Array;

let rec search = (arr, idx, predicate) =>
  switch (arr->Array.get(idx)) {
  | Some((k, v)) => predicate(k, v) ? search(arr, idx + 1, predicate) : false
  | None => true
  };

The analysis reports search might raise Invalid_argument (File.re:4:17) and is not annotated with @raises Invalid_argument. It appears reanalyse is incorrectly resolving this reference as OCaml's default Array.get.

Explicitly referencing the Belt module raises no warnings:

let rec search = (arr, idx, predicate) =>
  switch (arr->Belt.Array.get(idx)) {
  | Some((k, v)) => predicate(k, v) ? search(arr, idx + 1, predicate) : false
  | None => true
  };

I am using version 2.10.0

@TheSpyder here's some basic support for module aliases: #96

It handled examples such as:

module B = Belt;
module Array = B.Array;

Does that cover your usecase?

That looks right, yes. My code should only have one alias to resolve before it finds the correct function.

I'm working on building reanalyze myself to test the branch, but 4.06.1 doesn't build on macOS anymore so I'm going to have to do it in my linux VM ๐Ÿ˜‚

Well that was an effort, Ubuntu didn't upgrade to opam2 until v19.10, and I'm still on 18.04 LTS ๐Ÿ™„

Finally got it working after probably way too much effort - and yes the branch solves this issue in my real code. Thank you!

@TheSpyder I only meant to ask if you know of other patterns you're using. But thanks for testing the PR.
Btw binaries are produced in CI, e.g. https://app.circleci.com/pipelines/github/reason-association/reanalyze/166/workflows/929cc65a-86f5-4b99-b89b-5e8c27733aee/jobs/649/artifacts

I'll create a new release.

Btw binaries are produced in CI

Oh nice! That will save me a lot of time if this happens again ๐Ÿ˜‚

Thanks for resolving this so quickly ๐Ÿ˜