v2 / vlib / v / fmt / tests / comptime_if_duplicate_method_keep.vv
35 lines · 31 sloc · 556 bytes · 63bc769ce69a29caa6b9bf6300c7acea3ed78123
Raw
1// Test for issue #26271: v fmt fails on mutually exclusive $if blocks with duplicate method definitions
2module main
3
4struct MyType {
5 value int
6}
7
8$if foo ? {
9 pub fn (x MyType) str() string {
10 return 'foo mode'
11 }
12} $else {
13 pub fn (x MyType) str() string {
14 return 'normal mode'
15 }
16}
17
18$if bar ? {
19 fn (m MyType) debug() string {
20 return 'bar debug'
21 }
22} $else $if baz ? {
23 fn (m MyType) debug() string {
24 return 'baz debug'
25 }
26} $else {
27 fn (m MyType) debug() string {
28 return 'default debug'
29 }
30}
31
32fn main() {
33 t := MyType{42}
34 println(t.str())
35}
36