Skip to content

Commit

Permalink
Fix comparison of a nullable value to a non-nullable saved value. (#2…
Browse files Browse the repository at this point in the history
…1507)

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.
  • Loading branch information
bzbarsky-apple authored and web-flow committed Aug 2, 2022
1 parent 7571349 commit 39cff88
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/chip-tool/templates/tests/partials/value_equals.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -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}}));
Expand All @@ -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)}}
Expand Down

0 comments on commit 39cff88

Please sign in to comment.