File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,17 @@ fn (mut g Gen) assert_stmt(original_assert_statement ast.AssertStmt) {
17
17
}
18
18
mut node := original_assert_statement
19
19
g.writeln ('// assert' )
20
+
21
+ mut save_left := ast.empty_expr
22
+ mut save_right := ast.empty_expr
23
+
20
24
if mut node.expr is ast.InfixExpr {
21
25
if subst_expr := g.assert_subexpression_to_ctemp (node.expr.left, node.expr.left_type) {
26
+ save_left = node.expr.left
22
27
node.expr.left = subst_expr
23
28
}
24
29
if subst_expr := g.assert_subexpression_to_ctemp (node.expr.right, node.expr.right_type) {
30
+ save_right = node.expr.right
25
31
node.expr.right = subst_expr
26
32
}
27
33
}
@@ -56,6 +62,15 @@ fn (mut g Gen) assert_stmt(original_assert_statement ast.AssertStmt) {
56
62
g.gen_assert_postfailure_mode (node)
57
63
g.writeln ('}' )
58
64
}
65
+
66
+ if mut node.expr is ast.InfixExpr {
67
+ if node.expr.left is ast.CTempVar {
68
+ node.expr.left = save_left
69
+ }
70
+ if node.expr.right is ast.CTempVar {
71
+ node.expr.right = save_right
72
+ }
73
+ }
59
74
}
60
75
61
76
struct UnsupportedAssertCtempTransform {
Original file line number Diff line number Diff line change @@ -1816,6 +1816,8 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
1816
1816
cast_sym := g.table.sym (typ)
1817
1817
if cast_sym.info is ast.Aggregate {
1818
1818
typ = cast_sym.info.types[g.aggregate_type_idx]
1819
+ } else if expr.obj.ct_type_var == .smartcast {
1820
+ typ = g.unwrap_generic (g.comptime.get_comptime_var_type (expr))
1819
1821
}
1820
1822
}
1821
1823
// handling println( var or { ... })
Original file line number Diff line number Diff line change
1
+ pub type Any = []Any
2
+ | bool
3
+ | f32
4
+ | f64
5
+ | i16
6
+ | i64
7
+ | i8
8
+ | int
9
+ | map [string ]Any
10
+ | string
11
+ | u16
12
+ | u32
13
+ | u64
14
+ | u8
15
+
16
+ fn test_main () {
17
+ ana := Any ([Any ('' )])
18
+ name (ana)
19
+ match ana {
20
+ []Any {
21
+ for i := 0 ; i < ana.len; i++ {
22
+ name (ana[i])
23
+ }
24
+ }
25
+ else {
26
+ assert false
27
+ }
28
+ }
29
+ assert true
30
+ }
31
+
32
+ fn name [T](val T) {
33
+ $for v in val.variants {
34
+ if val is v {
35
+ dump (val.str ())
36
+ $if val is []Any {
37
+ assert val.str () == "[Any('')]"
38
+ } $else {
39
+ assert val.str () == ''
40
+ }
41
+ dump (val)
42
+ println (val)
43
+ }
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments