Skip to content

Commit d9dd274

Browse files
authored
fix(compiler): Correct in_function state when typing record properties (#2205)
1 parent d0038d3 commit d9dd274

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

compiler/src/typed/typecore.re

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,8 @@ and type_expect_ =
11051105
loc,
11061106
closed,
11071107
env,
1108-
(e, k) => k(type_label_exp(true, env, loc, ty_record, e)),
1108+
(e, k) =>
1109+
k(type_label_exp(~in_function, true, env, loc, ty_record, e)),
11091110
opath,
11101111
es,
11111112
),
@@ -1422,6 +1423,7 @@ and type_expect_ =
14221423
});
14231424
| PExpConstruct(cstr, arg) =>
14241425
type_construct(
1426+
~in_function,
14251427
env,
14261428
loc,
14271429
cstr,
@@ -2098,7 +2100,8 @@ and type_application = (~in_function=?, ~loc, env, funct, sargs) => {
20982100
(ordered_labels, omitted_args @ typed_args, instance(env, ty_ret));
20992101
}
21002102

2101-
and type_construct = (env, loc, lid, sarg, ty_expected_explained, attrs) => {
2103+
and type_construct =
2104+
(~in_function, env, loc, lid, sarg, ty_expected_explained, attrs) => {
21022105
let {ty: ty_expected, explanation} = ty_expected_explained;
21032106
let (sargs, is_record_cstr) =
21042107
switch (sarg) {
@@ -2215,7 +2218,7 @@ and type_construct = (env, loc, lid, sarg, ty_expected_explained, attrs) => {
22152218
let args =
22162219
List.map2(
22172220
(sarg, (ty_arg, ty_arg0)) =>
2218-
type_argument(~recarg, env, sarg, ty_arg, ty_arg0),
2221+
type_argument(~in_function?, ~recarg, env, sarg, ty_arg, ty_arg0),
22192222
sargs,
22202223
List.combine(ty_args, ty_args0),
22212224
);
@@ -2725,7 +2728,8 @@ and type_label_access = (env, srecord, lid) => {
27252728
(record, label, opath);
27262729
}
27272730

2728-
and type_label_exp = (create, env, loc, ty_expected, (lid, label, sarg)) => {
2731+
and type_label_exp =
2732+
(~in_function, create, env, loc, ty_expected, (lid, label, sarg)) => {
27292733
/* Here also ty_expected may be at generic_level */
27302734
begin_def();
27312735
let separate = Env.has_local_constraints(env);
@@ -2758,7 +2762,8 @@ and type_label_exp = (create, env, loc, ty_expected, (lid, label, sarg)) => {
27582762
} else {
27592763
Some(Btype.snapshot());
27602764
};
2761-
let arg = type_argument(env, sarg, ty_arg, instance(env, ty_arg));
2765+
let arg =
2766+
type_argument(~in_function?, env, sarg, ty_arg, instance(env, ty_arg));
27622767
end_def();
27632768
try(
27642769
{

compiler/test/suites/returns.re

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,32 @@ describe("early return", ({test, testSkip}) => {
108108
|},
109109
"7\n",
110110
);
111+
assertRun(
112+
"regression_2204_1",
113+
{|
114+
record Test {
115+
a: Number,
116+
}
117+
let test = () => {
118+
{ a: if (true) return 1 else 0, }
119+
return -1
120+
}
121+
print(test())
122+
|},
123+
"1\n",
124+
);
125+
assertRun(
126+
"regression_2204_2",
127+
{|
128+
record Test {
129+
a: Number,
130+
}
131+
let test = () => {
132+
Ok({ a: if (true) return 1 else 0, })
133+
return -1
134+
}
135+
print(test())
136+
|},
137+
"1\n",
138+
);
111139
});

0 commit comments

Comments
 (0)