From 6dc16521d35b477dbaabe2a4ed5b4aed44eb222c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 9 Aug 2022 11:44:36 -0700 Subject: [PATCH] Add illegal case of conditionally creating optional field Closes #3687 --- crates/reporting/tests/test_reporting.rs | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/crates/reporting/tests/test_reporting.rs b/crates/reporting/tests/test_reporting.rs index 9f491d239e..b082326b97 100644 --- a/crates/reporting/tests/test_reporting.rs +++ b/crates/reporting/tests/test_reporting.rs @@ -10397,4 +10397,34 @@ All branches in an `if` must have the same type! says this field is optional. Learn more about optional fields at TODO. "### ); + + test_report!( + create_value_with_conditionally_optional_record_field_type, + indoc!( + r#" + f : {a: Str, b ? Str} + f = if True then {a: ""} else {a: "b", b: ""} + f + "# + ), + @r###" + ── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─ + + Something is off with the `then` branch of this `if` expression: + + 4│ f : {a: Str, b ? Str} + 5│ f = if True then {a: ""} else {a: "b", b: ""} + ^^^^^^^ + + The 1st branch is a record of type: + + { a : Str } + + But the type annotation on `f` says it should be: + + { a : Str, b ? Str } + + Tip: Looks like the b field is missing. + "### + ); }