rescript-association / reanalyze

Experimental analyses for ReScript and OCaml: globally dead values/types, exception analysis, and termination analysis.
MIT License
277 stars 20 forks source link

Catching on exception from other module leads to incorrect warning #188

Closed fhammerschmidt closed 1 year ago

fhammerschmidt commented 1 year ago

Consider the following example:

module Test = {
  exception Nested

  @raises(Nested)
  let raises = async () => raise(Nested)
}

let raises = async () =>
  try await Test.raises() catch {
  | Test.Nested => Js.log("Not found")
  }

it gives me: raises might raise Nested (test.res:9:12) and is not annotated with @raises(Nested)

However, if I open Test instead:

module Test = {
  exception Nested

  @raises(Nested)
  let raises = async () => raise(Nested)
}

open Test

let raises = async () =>
  try await Test.raises() catch {
  | Nested => Js.log("Not found")
  }

Everything works fine

cristianoc commented 1 year ago

The exception analysis has a simple model for exception paths, which are taken literally. It does not try to resolve scope or aliasing.

cristianoc commented 1 year ago

Btw the analysis is now integrated in the editor extension, so this could be moved there.

fhammerschmidt commented 1 year ago

Ok, closing this in favor of https://github.com/rescript-lang/rescript-vscode/issues/716