Skip to content

Commit

Permalink
fix(compiler): Supply correct error for unbound record labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer committed May 7, 2022
1 parent db1fa4e commit cbe2226
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/src/typed/env.re
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,8 @@ let fold_modules = (f, lid, env, acc) =>
let fold_values = f => find_all(env => env.values, sc => sc.comp_values, f)
and fold_constructors = f =>
find_all_simple_list(env => env.constructors, sc => sc.comp_constrs, f)
and fold_labels = f =>
find_all_simple_list(env => env.labels, sc => sc.comp_labels, f)
and fold_types = f => find_all(env => env.types, sc => sc.comp_types, f)
and fold_modtypes = f =>
find_all(env => env.modtypes, sc => sc.comp_modtypes, f);
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/typed/env.rei
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ let fold_types:
'a
) =>
'a;
let fold_labels:
((label_description, 'a) => 'a, option(Identifier.t), t, 'a) => 'a;
/** Persistent structures are only traversed if they are already loaded. */

let fold_constructors:
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/typed/typetexp.re
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ let fold_values = fold_simple(Env.fold_values);
let fold_types = fold_simple(Env.fold_types);
let fold_modules = fold_persistent(Env.fold_modules);
let fold_constructors = fold_descr(Env.fold_constructors, d => d.cstr_name);
let fold_labels = fold_descr(Env.fold_labels, l => l.lbl_name);
let fold_modtypes = fold_simple(Env.fold_modtypes);

let type_attributes = attrs => {
Expand Down Expand Up @@ -743,7 +744,10 @@ let report_error = (env, ppf) =>
fprintf(ppf, "Unbound constructor %a", identifier, lid);
spellcheck(ppf, fold_constructors, env, lid);
}
| Unbound_label(_)
| Unbound_label(lid) => {
fprintf(ppf, "Unbound record label %a", identifier, lid);
spellcheck(ppf, fold_labels, env, lid);
}
| Unbound_class(_)
| Unbound_cltype(_) =>
failwith("Impossible: deprecated error type in typetexp")
Expand Down
5 changes: 5 additions & 0 deletions compiler/test/suites/records.re
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ describe("records", ({test, testSkip}) => {
"record Rec {foo: Number}; {foo: 4, bar: 4}",
"Unbound record label bar",
);
assertCompileError(
"record_err_3",
"let foo = \"\"; foo.charAt(0)",
"Unbound record label charAt",
);
assertRun(
"record_get_1",
"record Rec {foo: Number}; let bar = {foo: 4}; print(bar.foo)",
Expand Down

0 comments on commit cbe2226

Please sign in to comment.