alex

/

v Public
0 Issues 1 Contributor 0 Releases 4 Branches
Additions: 22 Deletions: 10 View patch
1 obj.add_terse('left_type', t.type_node(node.left_type))
2 obj.add_terse('right', t.expr(node.right))
3 obj.add_terse('right_type', t.type_node(node.right_type))
4+ obj.add_terse('promoted_type', t.type_node(node.promoted_type))
5 obj.add('auto_locked', t.string_node(node.auto_locked))
6 obj.add_terse('or_block', t.or_expr(node.or_block))
7 obj.add_terse('is_stmt', t.bool_node(node.is_stmt))
8
1 pos token.Pos
2 is_stmt bool
3 pub mut:
4- left Expr
5- right Expr
6- left_type Type
7- right_type Type
8- auto_locked string
9- or_block OrExpr
10+ left Expr
11+ right Expr
12+ left_type Type
13+ right_type Type
14+ promoted_type Type = void_type
15+ auto_locked string
16+ or_block OrExpr
17 //
18 ct_left_value_evaled bool
19 ct_left_value ComptTimeConstValue = empty_comptime_const_expr()
20
1 if node.op == .amp && left_type.is_bool() && right_type.is_bool() && right_type.is_ptr() {
2 pos := node.pos.extend(node.right.pos())
3 c.error('the right expression should be separated from the `&&` by a space', pos)
4+ node.promoted_type = ast.bool_type
5 return ast.bool_type
6 }
7 node.right_type = right_type
8 node.pos)
9 }
10 }
11+ node.promoted_type = ast.bool_type
12 return ast.bool_type
13 }
14 .plus, .minus, .mul, .div, .mod, .xor, .amp, .pipe {
15 c.error('only `==` and `!=` are defined on arrays', node.pos)
16 } else if left_sym.kind == .struct_
17 && (left_sym.info as ast.Struct).generic_types.len > 0 {
18+ node.promoted_type = ast.bool_type
19 return ast.bool_type
20 } else if left_sym.kind == .struct_ && right_sym.kind == .struct_
21 && node.op in [.eq, .lt] {
22 c.error('cannot append `${right_sym.name}` to `${left_sym.name}`', right_pos)
23 return ast.void_type
24 } else {
25- return c.check_shift(mut node, left_type, right_type)
26+ node.promoted_type = c.check_shift(mut node, left_type, right_type)
27+ return node.promoted_type
28 }
29 }
30 .right_shift {
31- return c.check_shift(mut node, left_type, right_type)
32+ node.promoted_type = c.check_shift(mut node, left_type, right_type)
33+ return node.promoted_type
34 }
35 .unsigned_right_shift {
36 modified_left_type := if !left_type.is_int() {
37 or_block: node.or_block
38 }
39
40- return c.check_shift(mut node, left_type, right_type)
41+ node.promoted_type = c.check_shift(mut node, left_type, right_type)
42+
43+ return node.promoted_type
44 }
45 .key_is, .not_is {
46 right_expr := node.right
47 }
48 }
49 }
50+ node.promoted_type = ast.bool_type
51 return ast.bool_type
52 }
53 .arrow { // `chan <- elem`
54 }
55 if left_type.nr_muls() > 0 && right_type.is_int() {
56 // pointer arithmetic is fine, it is checked in other places
57+ node.promoted_type = return_type
58 return return_type
59 }
60 c.error('infix expr: cannot use `${right_sym.name}` (right expression) as `${left_sym.name}`',
61 c.warn('`++` and `--` are statements, not expressions', node.pos)
62 }
63 */
64- return if node.op.is_relational() { ast.bool_type } else { return_type }
65+ node.promoted_type = if node.op.is_relational() { ast.bool_type } else { return_type }
66+ return node.promoted_type
67 }
68
69 fn (mut c Checker) check_div_mod_by_zero(expr ast.Expr, op_kind token.Kind) {
70