Skip to content

Commit addc550

Browse files
committed
feat(slang): when with Nil body is Nil
Signed-off-by: Ali Caglayan <alizter@gmail.com>
1 parent fe350c2 commit addc550

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/dune_lang/slang.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ let rec simplify = function
305305
let combined_sw = String_with_vars.make ~quoted loc parts in
306306
Literal combined_sw)
307307
else Form (loc, Concat (List.map xs ~f:simplify))
308+
| When (_, Nil) -> Nil
308309
| When (condition, t) ->
309310
let simplified_condition = simplify_blang condition in
310311
(match (simplified_condition : blang) with

test/expect-tests/dune_lang/slang_tests.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,9 @@ let%expect_test "when unknown" =
296296
[%expect {| When (Expr (Literal (template "%{pkg-self:x}")), Literal "hello") |}]
297297
;;
298298

299-
(* CR-soon Alizter: when with nil body should reduce to Nil *)
300299
let%expect_test "when unknown nil" =
301300
print_slang (Slang.when_ (expr (pform "x")) Slang.Nil);
302-
[%expect {| When (Expr (Literal (template "%{pkg-self:x}")), Nil) |}]
301+
[%expect {| Nil |}]
303302
;;
304303

305304
(* Slang: If *)

0 commit comments

Comments
 (0)