Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): Supply correct error for unbound record labels #1200

Merged
merged 1 commit into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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