Coercion hint suggests the inner type when the mismatch is nested
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- ocaml
- Domain
- compilers
Research direction
The fix is in compiler/ml/error_message_utils.ml: locate where the coercion hint is built from target_type and change it to use top_level_types. Compile the ReScript snippet from the issue to reproduce the wrong hint. Done when the suggested coercion is (make :> unit => iterable<int>) and the example compiles.
Written by the indexing model from the issue text.
Description
When a type mismatch is nested inside another type, the "compatible at runtime" hint suggests a coercion to the inner type instead of the whole expected type, and the suggested code doesn't compile.
let consume = (_f: unit => Iterable.t<int>) => ()
let make: unit => Generator.t<int, unit, unit> = %raw(`function* () { yield 1 }`)
let () = consume(make)
This has type: unit => Generator.t<int, unit, unit>
But this function argument is expecting: unit => Iterable.t<int>
The incompatible parts:
Generator.t<int, unit, unit> (defined as Generator.t<int, unit, unit>) vs
Iterable.t<int> (defined as iterable<int>)
Possible solutions:
- These types are compatible at runtime. You can use the coercion operator to convert to the expected type: (make :> iterable<int>)
Applying the suggestion fails with Type unit => Generator.t<int, unit, unit> is not a subtype of iterable<int>. The right suggestion is (make :> unit => iterable<int>), which compiles.
Cause
In compiler/ml/error_message_utils.ml, the hint checks Ctype.subtype on the top-level types of the trace (top_level_types, "Coercion should always target the top level types"), but builds the rewrite from target_type, which is the inner incompatible pair. Printing the top-level expected type instead should fix it.
(The doubled Generator.t<…> (defined as Generator.t<…>) in the same output is #8997.)
- Dominant language
- OCaml
- Stars
- 7.5k
- Forks
- 483
- Avg merge
- 19h 35m
- Merged PRs (30d)
- 208
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from rescript-lang/rescript
-
Per-constructor @unboxed is not compared across interfaces or coercionsPossibly taken @cknitt claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
rescript-lang/rescript#9038 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
rescript-lang/rescript#9006 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
rescript-lang/rescript#8997 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
rescript-lang/rescript#8994 ·
Maintainers usually reply within 1 day
-
@notUndefined in an interface is not checked against the implementationPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
rescript-lang/rescript#8964 · 1 comment ·
Maintainers usually reply within 1 day
All issues in rescript-lang/rescript
Similar issues
-
area:codegen backend:cuda backend:hip bug direction:input
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CrossGL/crosstl#3061 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
build
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
AOMediaCodec/SVT-AV1#2500 ·
-
bug goto-symex
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
leanprover/lean4#15925 ·
Maintainers usually reply within 1 day