Skip to content

Commit 23985b2

Browse files
committed
Fix let? unwrap early return for option types
When using `let? Some(x) = None` in a function returning `option<T>`, the early return was incorrectly returning a variable instead of None. This fixes the issue by explicitly returning None/Some values instead of using pattern-matched variables, ensuring correct type propagation and JS interop compatibility. Fixes #8085 Signed-Off-By: [Huijung Yoon] <[markup3604@gmail.com]>
1 parent 14721cb commit 23985b2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

compiler/frontend/bs_builtin_ppx.ml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,23 +248,21 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
248248
{
249249
Parsetree.pc_bar = None;
250250
pc_lhs =
251-
Ast_helper.Pat.alias
252-
(Ast_helper.Pat.construct ~loc {txt = Lident "None"; loc} None)
253-
{txt = "x"; loc};
251+
Ast_helper.Pat.construct ~loc {txt = Lident "None"; loc} None;
254252
pc_guard = None;
255-
pc_rhs = Ast_helper.Exp.ident ~loc {txt = Lident "x"; loc};
253+
pc_rhs = Ast_helper.Exp.construct ~loc {txt = Lident "None"; loc} None;
256254
}
257255
(* Option: continue on None, early-return on Some(x) *)
258256
| `Option_None ->
259257
{
260258
Parsetree.pc_bar = None;
261259
pc_lhs =
262-
Ast_helper.Pat.alias
263-
(Ast_helper.Pat.construct ~loc {txt = Lident "Some"; loc}
264-
(Some (Ast_helper.Pat.any ~loc ())))
265-
{txt = "x"; loc};
260+
Ast_helper.Pat.construct ~loc {txt = Lident "Some"; loc}
261+
(Some (Ast_helper.Pat.var ~loc {txt = "x"; loc}));
266262
pc_guard = None;
267-
pc_rhs = Ast_helper.Exp.ident ~loc {txt = Lident "x"; loc};
263+
pc_rhs =
264+
Ast_helper.Exp.construct ~loc {txt = Lident "Some"; loc}
265+
(Some (Ast_helper.Exp.ident ~loc {txt = Lident "x"; loc}));
268266
}
269267
in
270268
default_expr_mapper self

0 commit comments

Comments
 (0)