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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): Fix disambiguation of record label access #2072

Merged
merged 1 commit into from Mar 16, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/typed/typecore.re
Expand Up @@ -2592,7 +2592,7 @@ and type_label_access = (env, srecord, lid) => {
let opath =
try({
let (p0, p, _) = extract_concrete_record(env, ty_exp);
Some((p0, p, repr(ty_exp).level == generic_level));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been broken for quite a while, long enough that I'm too lazy to find out. We did some cleanup in #1751 where you can see what the code was before. Most of the logic around principal types was commented out, including a condition that would consider this to be true if principal types were not enabled. I imagine we accidentally commented that out way back in the day.

Some((p0, p, true));
}) {
| Not_found => None
};
Expand Down
27 changes: 27 additions & 0 deletions compiler/test/suites/records.re
Expand Up @@ -13,6 +13,7 @@ describe("records", ({test, testSkip}) => {
let assertCompileError = makeCompileErrorRunner(test);
let assertRun = makeRunner(test_or_skip);
let assertWarning = makeWarningRunner(test);
let assertNoWarning = makeNoWarningRunner(test);

assertRun(
"record_1",
Expand Down Expand Up @@ -229,4 +230,30 @@ describe("records", ({test, testSkip}) => {
"record Rec {foo: Number, bar: Number}; let a = {foo: 1, bar: 2}; let b = {...a, foo: 2, bar: 3}",
Warnings.UselessRecordSpread,
);

assertWarning(
"disambiguation_1",
{|
record A { field: Number }
record B { field: Number }
x => x.field
|},
Warnings.AmbiguousName(["field"], ["B", "A"], false),
);
assertNoWarning(
"disambiguation_2",
{|
record A { field: Number }
record B { field: Number }
(x: A) => x.field
|},
);
assertNoWarning(
"disambiguation_3",
{|
record A { field: Number }
record B { field: Number }
(x: B) => x.field
|},
);
});