alex

/

v Public
0 Issues 1 Contributor 0 Releases 4 Branches
Additions: 16 Deletions: 75 View patch
1 'do_not_remove',
2 'vlib/v/tests/const_fixed_array_containing_references_to_itself_test.v', // error C2099: initializer is not a constant
3 'vlib/v/tests/const_and_global_with_same_name_test.v', // error C2099: initializer is not a constant
4- 'vlib/v/tests/sumtype_as_cast_test.v', // error: Compound statement expression cannot support
5 ]
6 skip_on_windows = [
7 'do_not_remove',
8
1 mut expr_type_sym := g.table.sym(g.unwrap_generic(node.expr_type))
2 if mut expr_type_sym.info is ast.SumType {
3 dot := if node.expr_type.is_ptr() { '->' } else { '.' }
4- $if !msvc {
5- if node.expr is ast.CallExpr {
6- tmp_var := g.new_tmp_var()
7- expr_styp := g.typ(node.expr_type)
8- g.write('({ ${expr_styp} ${tmp_var} = ')
9- g.expr(node.expr)
10- g.write('; ')
11- if sym.info is ast.FnType {
12- g.write('/* as */ (${styp})__as_cast(')
13- } else {
14- g.write('/* as */ *(${styp}*)__as_cast(')
15- }
16- g.write(tmp_var)
17- g.write(dot)
18- g.write('_${sym.cname},')
19- g.write(tmp_var)
20- g.write(dot)
21- sidx := g.type_sidx(unwrapped_node_typ)
22- g.write('_typ, ${sidx}); }) /*expected idx: ${sidx}, name: ${sym.name} */ ')
23- } else {
24- if sym.info is ast.FnType {
25- g.write('/* as */ (${styp})__as_cast(')
26- } else {
27- g.write('/* as */ *(${styp}*)__as_cast(')
28- }
29- g.write('(')
30- g.expr(node.expr)
31- g.write(')')
32- g.write(dot)
33- g.write('_${sym.cname},')
34- g.write('(')
35- g.expr(node.expr)
36- g.write(')')
37- g.write(dot)
38- // g.write('typ, /*expected:*/$node.typ)')
39- sidx := g.type_sidx(unwrapped_node_typ)
40- g.write('_typ, ${sidx}) /*expected idx: ${sidx}, name: ${sym.name} */ ')
41- }
42- } $else {
43- if sym.info is ast.FnType {
44- g.write('/* as */ (${styp})__as_cast(')
45- } else {
46- g.write('/* as */ *(${styp}*)__as_cast(')
47- }
48- g.write('(')
49- g.expr(node.expr)
50- g.write(')')
51- g.write(dot)
52- g.write('_${sym.cname},')
53- g.write('(')
54- g.expr(node.expr)
55- g.write(')')
56- g.write(dot)
57- // g.write('typ, /*expected:*/$node.typ)')
58- sidx := g.type_sidx(unwrapped_node_typ)
59- g.write('_typ, ${sidx}) /*expected idx: ${sidx}, name: ${sym.name} */ ')
60+ if sym.info is ast.FnType {
61+ g.write('/* as */ (${styp})__as_cast(')
62+ } else {
63+ g.write('/* as */ *(${styp}*)__as_cast(')
64 }
65+ g.write('(')
66+ g.expr(node.expr)
67+ g.write(')')
68+ g.write(dot)
69+ g.write('_${sym.cname},')
70+ g.write('(')
71+ g.expr(node.expr)
72+ g.write(')')
73+ g.write(dot)
74+ // g.write('typ, /*expected:*/$node.typ)')
75+ sidx := g.type_sidx(unwrapped_node_typ)
76+ g.write('_typ, ${sidx}) /*expected idx: ${sidx}, name: ${sym.name} */ ')
77
78 // fill as cast name table
79 for variant in expr_type_sym.info.variants {
80
1deleted file mode 100644
2-type Sum = int | string
3-
4-struct Count {
5-mut:
6- count int
7-}
8-
9-fn (mut c Count) ret_sum() Sum {
10- c.count++
11- return c.count
12-}
13-
14-fn test_sumtype_as_cast() {
15- mut cnt := Count{22}
16- _ := cnt.ret_sum() as int
17- println(cnt)
18- assert cnt.count == 23
19-}
20