rescript-lang / rescript-lang/rescript

Improve error message when adding type to generic application

Open
#7,969 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
OCaml
Stars
7.5k
Forks
485
Avg merge
1d 2h
Merged PRs (30d)
55

Description

Consider

https://rescript-lang.org/try?version=v12.0.0-beta.13&module=esmodule&code=LYewJgrgNgpgBAdRgIwIIAUCScC8cDeAUHAJCiSxwAiA8gLIbZ5EkkAuAngA7wyzAwAdm2JwAvnEJjChWGzh8YA4QCUYAMwDCIAE46YAY3kAuOGoCGRgHT71AHgBy0KOeSwrbO0jRYrtBr6KymwAfCG4ZjCWbFYQAM4wauoAFE5QLm4wVoLOAJSyMPJBQmxJERbW8YkaXiiMfvT1xcIhqc6u7jnp+UA

module WebAPI = {
 	module DOMAPI = {
		type element
  } 
}

let elementRefCorrect : React.ref<Nullable.t<WebAPI.DOMAPI.element>> = React.useRef(Nullable.null)
let elementRef = React.useRef<WebAPI.DOMAPI.element>(Nullable.null)

In F#, you can specify the React.useRef<WebAPI.DOMAPI.element> syntax.
I can live with the fact that ReScript doesn't have the same syntax as F#.
But the error message is very confusing:

Type Errors
[E] Line 8, column 30:
The value element can't be found in WebAPI.DOMAPI

The type does exists, whatever I'm going for syntax-wise is the issue here.
Could we improve this?
Thoughts @zth?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ReScript Try reproducer in the issue and trace the compiler's type-error reporting for the React.useRef generic application. The work is done when this invalid syntax produces a diagnostic that explains the syntax problem instead of incorrectly saying WebAPI.DOMAPI.element cannot be found.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.