Type errors print a type twice when it is reached through a module alias
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- ocaml
- Domain
- compilers
Research direction
Start in compiler/ml/printtyp.ml at same_path and read how it compares paths used by type_expansion and super_type_expansion; the issue points to alias normalization via Env.normalize_path. Check the type mismatch and coercion examples, then run the snapshot test GeneratorResumeTypeWidening mentioned in the issue. Done means aliased types print once, matching the output for the equivalent unaliased type.
Written by the indexing model from the issue text.
Description
When a type is reached through a module alias, type errors print it twice, once as written and once as its "expansion", which prints identically. This hits every stdlib type used through Stdlib's aliases (Map.t, Generator.t, …).
Type mismatch
let f = (x: Map.t<string, int>): Map.t<string, string> => x
This has type: Map.t<string, int> (defined as Map.t<string, int>)
But it's expected to have type:
Map.t<string, string> (defined as Map.t<string, string>)
Coercion
let widen = (g: Generator.t<int, unit, [#X]>) => (g :> Generator.t<int, unit, [#X | #Y]>)
Type Generator.t<int, unit, [#X]> = Generator.t<int, unit, [#X]>
is not a subtype of
Generator.t<int, unit, [#X | #Y]> = Generator.t<int, unit, [#X | #Y]>
Expected: This has type: Map.t<string, int> and Type Generator.t<int, unit, [#X]> is not a subtype of Generator.t<int, unit, [#X | #Y]>, as printed when the type is written without the alias (Stdlib_Map.t<string, int>).
With a local alias the output is not identical but still says nothing, since an alias is the same module:
module Inner = {
type t<'a>
}
module A = Inner
let m = (x: A.t<[#X]>) => (x :> A.t<[#X | #Y]>)
Type A.t<[#X]> = Inner.t<[#X]> is not a subtype of
A.t<[#X | #Y]> = Inner.t<[#X | #Y]>
Likely cause
same_path in compiler/ml/printtyp.ml, which decides whether to print the expansion (type_expansion, super_type_expansion), compares the paths from best_type_path with Path.same. That doesn't normalize module aliases, so Stdlib.Map.t and its expansion Stdlib_Map.t count as different; the short-path printer then prints both as Map.t. Comparing the alias-normalized paths (Env.normalize_path) should fix it.
Found while adding a test for #8981, whose GeneratorResumeTypeWidening snapshot records the doubled output.
- 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
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
rescript-lang/rescript#9037 ·
Maintainers usually reply within 1 day
-
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 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
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
build
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
AOMediaCodec/SVT-AV1#2500 ·
-
SIGSEGV in symex on __builtin_constant_p of a void expressionPossibly taken A pull request linked to this issue is open or already merged. Openbug goto-symex
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day