diff --git a/vlib/v/tests/options/option_unwrap_ifexpr_test.v b/vlib/v/tests/options/option_unwrap_ifexpr_test.v new file mode 100644 index 00000000000000..267f67c23c5121 --- /dev/null +++ b/vlib/v/tests/options/option_unwrap_ifexpr_test.v @@ -0,0 +1,28 @@ +type TestSmart = ?string | int + +fn test_simple_case() { + o := ?string('abc') + dump(o) + a := if o == none { + 'none' + } else { + '${o} exists' + } + dump(a) + assert a == 'abc exists' +} + +fn test_comptime_smartcast() { + t := TestSmart(?string('foobar')) + $for v in TestSmart.variants { + if t is v { + $if t is ?string { + if t == none { + panic('error') + } else { + assert t == 'foobar' + } + } + } + } +}