| 1 | fn count_muls[T](val T) int { |
| 2 | mut nr_muls := 0 |
| 3 | dump(T.indirections) |
| 4 | dump(typeof(val).indirections) |
| 5 | $if (int(typeof(val).idx) >> 16) & 0xff == 0 { |
| 6 | assert T.indirections == 0 |
| 7 | } $else { |
| 8 | nr_muls = (int(typeof(val).idx) >> 16) & 0xff |
| 9 | } |
| 10 | assert nr_muls == T.indirections |
| 11 | $if T.indirections > 0 { |
| 12 | nr_muls = (int(typeof(val).idx) >> 16) & 0xff |
| 13 | } |
| 14 | assert nr_muls == T.indirections |
| 15 | $if T.indirections != 0 { |
| 16 | nr_muls = (int(typeof(val).idx) >> 16) & 0xff |
| 17 | } |
| 18 | assert nr_muls == T.indirections |
| 19 | return nr_muls |
| 20 | } |
| 21 | |
| 22 | fn test_main() { |
| 23 | val := '' |
| 24 | pval := &val |
| 25 | ppval := &pval |
| 26 | assert count_muls(val) == 0 |
| 27 | assert count_muls(pval) == 1 |
| 28 | assert count_muls(ppval) == 2 |
| 29 | } |
| 30 | |