From 23985b2445f022c46f48fd5b755d9a974300fe29 Mon Sep 17 00:00:00 2001 From: HuijungYoon Date: Sun, 14 Dec 2025 17:12:03 +0900 Subject: [PATCH] Fix let? unwrap early return for option types When using `let? Some(x) = None` in a function returning `option`, 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]> --- compiler/frontend/bs_builtin_ppx.ml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/compiler/frontend/bs_builtin_ppx.ml b/compiler/frontend/bs_builtin_ppx.ml index 8960731163..18d8c442d3 100644 --- a/compiler/frontend/bs_builtin_ppx.ml +++ b/compiler/frontend/bs_builtin_ppx.ml @@ -248,23 +248,21 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) { Parsetree.pc_bar = None; pc_lhs = - Ast_helper.Pat.alias - (Ast_helper.Pat.construct ~loc {txt = Lident "None"; loc} None) - {txt = "x"; loc}; + Ast_helper.Pat.construct ~loc {txt = Lident "None"; loc} None; pc_guard = None; - pc_rhs = Ast_helper.Exp.ident ~loc {txt = Lident "x"; loc}; + pc_rhs = Ast_helper.Exp.construct ~loc {txt = Lident "None"; loc} None; } (* Option: continue on None, early-return on Some(x) *) | `Option_None -> { Parsetree.pc_bar = None; pc_lhs = - Ast_helper.Pat.alias - (Ast_helper.Pat.construct ~loc {txt = Lident "Some"; loc} - (Some (Ast_helper.Pat.any ~loc ()))) - {txt = "x"; loc}; + Ast_helper.Pat.construct ~loc {txt = Lident "Some"; loc} + (Some (Ast_helper.Pat.var ~loc {txt = "x"; loc})); pc_guard = None; - pc_rhs = Ast_helper.Exp.ident ~loc {txt = Lident "x"; loc}; + pc_rhs = + Ast_helper.Exp.construct ~loc {txt = Lident "Some"; loc} + (Some (Ast_helper.Exp.ident ~loc {txt = Lident "x"; loc})); } in default_expr_mapper self