rescript-lang / rescript-lang/rescript-vscode
False Positive When Using First Class Module Type Alias
Nobody has claimed this yet.
- Dominant language
- ReScript
- Stars
- 354
- Forks
- 63
- Avg merge
- 11h 29m
- Merged PRs (30d)
- 1
Description
I ran across a case where false positives were being generated for first class modules. In particular the false positive was only generated if a type alias was used for the module's type. I have recreated a minimal reproduction of the issue below. I have already taken one attempt at fixing this myself but it introduced more false positives in our codebase. Any help or pointers would be appreciated!
Example First Class Module
module type ModuleType = {
type t
}
module MakeWithType = (A: ModuleType): (ModuleType with type t = A.t) => {
type t = A.t
}
let main = () => {
let moduleA: module(ModuleType with type t = int) = module(
MakeWithType({
type t = int
})
)
let module(A) = moduleA
let intA: A.t = 1
Js.log(intA)
}
main()
Example First Class Module with False Positive
module type ModuleType = {
type t
}
module MakeWithType = (A: ModuleType): (ModuleType with type t = A.t) => {
type t = A.t
}
type moduleAlias<'a> = module(ModuleType with type t = 'a)
let main = () => {
// Marked as dead (transitively) due to type alias
let moduleA: moduleAlias<int> = module(
MakeWithType({
type t = int
})
)
// Marked as dead (false positive)
let module(A) = moduleA
// Live usage of module A
let intA: A.t = 1
Js.log(intA)
}
main()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal ReScript reproduction in the issue and run it through the plugin's diagnostics to observe the dead-code warnings. Trace the first-class module and type-alias analysis, then verify that moduleA and module(A) are not marked dead while the live use of A.t remains recognized.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100