From 21c463ed94315c2c90b8f849d03978d2a15075d4 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Mon, 1 Aug 2022 21:24:25 -0700 Subject: [PATCH] Fix comparison of a nullable value to a non-nullable saved value. (#21507) (#21516) The code generated for the case when a non-nullable value was saved via saveAs and then a nullable value was being compared to it did not compile, because we would try to do .IsNull() and .Value() on the non-nullable saved value. The changes here check whether the saved value is actually nullable and generate code accordingly, instead of assuming that if we're comparing a nullable to something the something must also be nullable. Co-authored-by: Boris Zbarsky --- .../chip-tool/templates/tests/partials/value_equals.zapt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/chip-tool/templates/tests/partials/value_equals.zapt b/examples/chip-tool/templates/tests/partials/value_equals.zapt index e387036b293662..8e9b9d021c884b 100644 --- a/examples/chip-tool/templates/tests/partials/value_equals.zapt +++ b/examples/chip-tool/templates/tests/partials/value_equals.zapt @@ -6,6 +6,7 @@ VerifyOrReturn(CheckValueNull("{{label}}", {{actual}})); {{else}} {{#if (chip_tests_variables_has expected)}} + {{#if (chip_tests_variables_is_nullable expected)}} {{! Expected value is also a nullable. }} if ({{expected}}.IsNull()) { VerifyOrReturn(CheckValueNull("{{label}}", {{actual}})); @@ -15,6 +16,10 @@ VerifyOrReturn(CheckValueNonNull("{{label}}", {{actual}})); {{>valueEquals label=(concat label ".Value()") actual=(concat actual ".Value()") expected=(concat expected ".Value()") isNullable=false keepAsExpected=true depth=(incrementDepth depth)}} } + {{else}} + VerifyOrReturn(CheckValueNonNull("{{label}}", {{actual}})); + {{>valueEquals label=(concat label ".Value()") actual=(concat actual ".Value()") expected=expected isNullable=false keepAsExpected=true depth=(incrementDepth depth)}} + {{/if}} {{else}} VerifyOrReturn(CheckValueNonNull("{{label}}", {{actual}})); {{>valueEquals label=(concat label ".Value()") actual=(concat actual ".Value()") expected=expected isNullable=false depth=(incrementDepth depth)}}