1struct Abc { 2mut: 3 val string 4} 5struct Xyz { 6 name string 7} 8type Alphabet = Abc | Xyz 9 10fn test_if_smartcast() { 11 x := Alphabet(Abc{'test'}) 12 if x is Abc { 13 assert x.val == 'test' 14 } 15} 16 17fn test_mutable() { 18 mut x := Alphabet(Abc{'test'}) 19 if x is Abc { 20 y := Abc{} 21 mut mx := x 22 mx = &y 23 assert mx == &y 24 assert u64(mx) == u64(&y) 25 assert u64(x) != u64(&y) 26 } 27} 28 29fn test_nested_if_smartcast() { 30 x := Alphabet(Abc{'test'}) 31 y := Alphabet(Xyz{'foo'}) 32 if x is Abc { 33 if y is Xyz { 34 assert y.name == 'foo' 35 } 36 } 37} 38 39fn test_as_cast() { 40 x := Alphabet(Abc{'test'}) 41 if x is Abc as test { 42 assert test.val == 'test' 43 } 44} 45 46struct Test { 47 abc Alphabet 48} 49 50fn test_mutable_with_struct() { 51 mut x := Test{Abc{'test'}} 52 if x.abc is Abc as test { 53 mut ttt := test 54 assert u64(ttt) == u64(ttt) 55 ttt.val = 'test' 56 assert ttt.val == 'test' 57 } 58} 59 60fn test_as_cast_with_struct() { 61 x := Test{Abc{'test'}} 62 if x.abc is Abc as test { 63 assert test.val == 'test' 64 } 65} 66