Skip to content

Commit 86e1bc0

Browse files
authored
fix(compiler): Supply correct error for unbound record labels (#1200)
1 parent 574472f commit 86e1bc0

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

compiler/src/typed/env.re

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,8 @@ let fold_modules = (f, lid, env, acc) =>
25862586
let fold_values = f => find_all(env => env.values, sc => sc.comp_values, f)
25872587
and fold_constructors = f =>
25882588
find_all_simple_list(env => env.constructors, sc => sc.comp_constrs, f)
2589+
and fold_labels = f =>
2590+
find_all_simple_list(env => env.labels, sc => sc.comp_labels, f)
25892591
and fold_types = f => find_all(env => env.types, sc => sc.comp_types, f)
25902592
and fold_modtypes = f =>
25912593
find_all(env => env.modtypes, sc => sc.comp_modtypes, f);

compiler/src/typed/env.rei

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ let fold_types:
275275
'a
276276
) =>
277277
'a;
278+
let fold_labels:
279+
((label_description, 'a) => 'a, option(Identifier.t), t, 'a) => 'a;
278280
/** Persistent structures are only traversed if they are already loaded. */
279281

280282
let fold_constructors:

compiler/src/typed/typetexp.re

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ let fold_values = fold_simple(Env.fold_values);
581581
let fold_types = fold_simple(Env.fold_types);
582582
let fold_modules = fold_persistent(Env.fold_modules);
583583
let fold_constructors = fold_descr(Env.fold_constructors, d => d.cstr_name);
584+
let fold_labels = fold_descr(Env.fold_labels, l => l.lbl_name);
584585
let fold_modtypes = fold_simple(Env.fold_modtypes);
585586

586587
let type_attributes = attrs => {
@@ -743,7 +744,10 @@ let report_error = (env, ppf) =>
743744
fprintf(ppf, "Unbound constructor %a", identifier, lid);
744745
spellcheck(ppf, fold_constructors, env, lid);
745746
}
746-
| Unbound_label(_)
747+
| Unbound_label(lid) => {
748+
fprintf(ppf, "Unbound record label %a", identifier, lid);
749+
spellcheck(ppf, fold_labels, env, lid);
750+
}
747751
| Unbound_class(_)
748752
| Unbound_cltype(_) =>
749753
failwith("Impossible: deprecated error type in typetexp")

compiler/test/suites/records.re

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ describe("records", ({test, testSkip}) => {
4646
"record Rec {foo: Number}; {foo: 4, bar: 4}",
4747
"Unbound record label bar",
4848
);
49+
assertCompileError(
50+
"record_err_3",
51+
"let foo = \"\"; foo.charAt(0)",
52+
"Unbound record label charAt",
53+
);
4954
assertRun(
5055
"record_get_1",
5156
"record Rec {foo: Number}; let bar = {foo: 4}; print(bar.foo)",

0 commit comments

Comments
 (0)