Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False "unused open" warning #6752

Open
cwstra opened this issue May 13, 2024 · 0 comments
Open

False "unused open" warning #6752

cwstra opened this issue May 13, 2024 · 0 comments
Labels

Comments

@cwstra
Copy link

cwstra commented May 13, 2024

Examples run in the playground, with v11.1.0.

Consider the following snippet:

module M = {
  type t = {
    id: string,
    value?: int,
  }
}

open M
let value = [{id: "id"}]

Pasting this example code into the playground successfully compiles, but with a warning:

[W] Line 8, column 0:
unused open M.

Yet, if we remove this 'unused' open,

module M = {
  type t = {
    id: string,
    value?: int,
  }
}

let value = [{id: "id"}]

we get a compiler error (as expected by module scoping)

[E] Line 8, column 14:
The record field id can't be found.

Interestingly, the warning disappears if remove the value field:

module M = {
  type t = {
    id: string,
  }
}

open M
let value = [{id: "id"}]

or pass a value for it:

module M = {
  type t = {
    id: string,
    value?: int
  }
}

open M
let value = [{id: "id",  value: 1}]
@cknitt cknitt added the bug label May 27, 2024
cristianoc added a commit that referenced this issue May 30, 2024
When disambiguating record types, there's a check that all the labels are supplied when constructing a record.
While not supplying all the labels is supported in case of optional labels, the order of disambiguation is affected by the presence of optional labels.

Example:

```res
type t1 = {x:int, y:int}
type t2 = {x:int, y:int, z?:int}

let v = {x:3, y:4}
```

Currently `v` has type `t1`, while it's perfectly fine for it to have type `t2`.
In particular, the normal shadowing behaviour that applies without optional labels, does not happen. (If you remove `z` from the second type definition, then the normal shadowing happens, and `v` gets type `t2`.

This wip changes the disambiguation so that supplying at least all the mandatory labels is enough in disambiguation.

The change also addresses the issue #6752 of spurious warning of unused open.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants