From 1a52da9f62187823b40e4bdd0c34f229e5189e50 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 19 Jun 2021 23:50:09 +0800 Subject: [PATCH] tests: add as_cast_already_smartcast_sumtype_test.v (#10517) --- .../as_cast_already_smartcast_sumtype_test.v | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 vlib/v/tests/as_cast_already_smartcast_sumtype_test.v diff --git a/vlib/v/tests/as_cast_already_smartcast_sumtype_test.v b/vlib/v/tests/as_cast_already_smartcast_sumtype_test.v new file mode 100644 index 0000000000..e6a2a8e919 --- /dev/null +++ b/vlib/v/tests/as_cast_already_smartcast_sumtype_test.v @@ -0,0 +1,30 @@ +struct S1 { + s1 string = 'abc' +} + +struct Empty { +} + +type Sum = Empty | S1 + +fn test_as_cast_already_smartcast_sumtype() { + a := Sum(S1{}) + if a is S1 { + println('if expr: $a.s1') + assert a.s1 == 'abc' + v1 := a as S1 + println('if expr (as cast): $v1.s1') + assert v1.s1 == 'abc' + } + + match a { + S1 { + println('match expr: $a.s1') + assert a.s1 == 'abc' + v1 := a as S1 + println('match expr (as cast): $v1.s1') + assert v1.s1 == 'abc' + } + else {} + } +}