You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bd4a722
Browse filesBrowse the repository at this point in the historyBrowse files
Name exceptions by where they are defined in exception analysis
Why:
A review of 81ce8eb found that it broke common code. A @throws
naming another module's exception got the callee's module put in
front (`ThrowsRepo.ThrowsErrors.NotFound`). A binding's own @throws
was still compared as written, so `@throws(Bad)` after
`open ThrowsErrors`, an alias, or any name in a namespaced project
warned twice. And how a name resolved depended on whether some other
file caught it.
Every exception now has one name: where it is defined. A file's own
exceptions are named with the file and module (`File.M.E`), a namespace
is left out, and `exception E = Lib.F` is `Lib.F`. Every @throws name is
resolved in the scope it was written in: the module and the modules
around it, what they include, and the file's opens and module aliases.
The first candidate the project defines, catches or throws wins. A
binding's own @throws is resolved the same way. Messages leave out the
current file's name, so existing warnings read as before.
A namespaced callee path now drops the namespace (`Ns.Lib.f` is
`Lib.f`), so calls in namespaced projects find the binding's @throws.
A functor parameter's declarations are still named after the parameter:
`X.get`'s `@throws(E)` is `X.E`. A fixture shows this limit.
Reanalyze modified (names from another module, open and alias):
Example:
// ThrowsErrors.res
exception NotFound
exception Bad(string)
// ThrowsRepo.res
@throws(ThrowsErrors.NotFound)
let find = x => x > 0 ? x : throw(ThrowsErrors.NotFound)
open ThrowsErrors
@throws(Bad)
let viaOpen = x => x > 0 ? x : throw(Bad("negative"))
// ThrowsRepoCalls.res
let catchFind = x =>
try ThrowsRepo.find(x) catch {
| ThrowsErrors.NotFound => 0
}
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
Exception Analysis
ThrowsRepo.res:17:5-11
viaOpen might throw ThrowsErrors.Bad (ThrowsRepo.res:17:31) and is annotated with redundant @throws(Bad)
Exception Analysis
ThrowsRepoCalls.res:3:5-13
catchFind might throw ThrowsRepo.ThrowsErrors.NotFound (ThrowsRepoCalls.res:4:6) and is not annotated with @throws(ThrowsRepo.ThrowsErrors.NotFound)
Exception Analysis
ThrowsRepoCalls.res:24:5-13
annotated might throw ThrowsRepo.ThrowsErrors.NotFound (ThrowsRepoCalls.res:24:21) and is annotated with redundant @throws(ThrowsErrors.NotFound)
…
Analysis reported 63 issues (Exception Analysis:63)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
Exception Analysis
ThrowsLibExnCalls.res:101:7-12
caught might throw X.E (ThrowsLibExnCalls.res:102:8) and is not annotated with @throws(X.E)
Analysis reported 47 issues (Exception Analysis:47)
Review: Why not resolve @throws in the type checker, which has the environment? That would be exact, and would also handle functor parameters, but it is a much bigger compiler change. The .cmt keeps no environments, so reanalyze rebuilds the scope it needs from the file.
Review: Can a guess pick the wrong exception? Only when two candidates both exist, as a module's own E and an E it opens. The module's own name is tried first, then what it includes, then the outer modules, then the opens, which can differ from the language's shadowing order.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
0 commit comments