checker: c2v fixes (#14091)
parent
f3ce968124
commit
0065dba88a
|
@ -429,13 +429,13 @@ fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type ast.Type, right
|
|||
|
||||
pub fn (mut c Checker) promote(left_type ast.Type, right_type ast.Type) ast.Type {
|
||||
if left_type.is_any_kind_of_pointer() {
|
||||
if right_type.is_int() {
|
||||
if right_type.is_int() || c.pref.translated {
|
||||
return left_type
|
||||
} else {
|
||||
return ast.void_type
|
||||
}
|
||||
} else if right_type.is_any_kind_of_pointer() {
|
||||
if left_type.is_int() {
|
||||
if left_type.is_int() || c.pref.translated {
|
||||
return right_type
|
||||
} else {
|
||||
return ast.void_type
|
||||
|
@ -489,6 +489,8 @@ fn (c &Checker) promote_num(left_type ast.Type, right_type ast.Type) ast.Type {
|
|||
return if idx_lo == ast.i64_type_idx { type_lo } else { type_hi }
|
||||
} else if idx_hi - idx_lo < (ast.byte_type_idx - ast.i8_type_idx) {
|
||||
return type_lo // conversion unsigned -> signed if signed type is larger
|
||||
} else if c.pref.translated {
|
||||
return type_hi
|
||||
} else {
|
||||
return ast.void_type // conversion signed -> unsigned not allowed
|
||||
}
|
||||
|
|
|
@ -442,7 +442,7 @@ pub fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
|
|||
c.check_valid_pascal_case(node.name, 'type alias', node.pos)
|
||||
}
|
||||
c.ensure_type_exists(node.parent_type, node.type_pos) or { return }
|
||||
typ_sym := c.table.sym(node.parent_type)
|
||||
mut typ_sym := c.table.sym(node.parent_type)
|
||||
if typ_sym.kind in [.placeholder, .int_literal, .float_literal] {
|
||||
c.error('unknown type `$typ_sym.name`', node.type_pos)
|
||||
} else if typ_sym.kind == .alias {
|
||||
|
@ -594,6 +594,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||
}
|
||||
}
|
||||
mut return_type := left_type
|
||||
|
||||
if node.op != .key_is {
|
||||
match mut node.left {
|
||||
ast.Ident, ast.SelectorExpr {
|
||||
|
@ -681,7 +682,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||
left_sym = c.table.sym((left_sym.info as ast.Alias).parent_type)
|
||||
}
|
||||
// Check if the alias type is not a primitive then allow using operator overloading for aliased `arrays` and `maps`
|
||||
if left_sym.kind == .alias && left_sym.info is ast.Alias
|
||||
if !c.pref.translated && left_sym.kind == .alias && left_sym.info is ast.Alias
|
||||
&& !(c.table.sym((left_sym.info as ast.Alias).parent_type).is_primitive()) {
|
||||
if left_sym.has_method(node.op.str()) {
|
||||
if method := left_sym.find_method(node.op.str()) {
|
||||
|
@ -699,7 +700,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||
c.error('mismatched types `$left_name` and `$right_name`', left_right_pos)
|
||||
}
|
||||
}
|
||||
} else if right_sym.kind == .alias && right_sym.info is ast.Alias
|
||||
} else if !c.pref.translated && right_sym.kind == .alias && right_sym.info is ast.Alias
|
||||
&& !(c.table.sym((right_sym.info as ast.Alias).parent_type).is_primitive()) {
|
||||
if right_sym.has_method(node.op.str()) {
|
||||
if method := right_sym.find_method(node.op.str()) {
|
||||
|
@ -806,6 +807,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||
if node.op in [.div, .mod] {
|
||||
c.check_div_mod_by_zero(node.right, node.op)
|
||||
}
|
||||
|
||||
return_type = promoted_type
|
||||
}
|
||||
}
|
||||
|
|
|
@ -781,6 +781,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
|||
if func.params.len == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
param := if func.is_variadic && i >= func.params.len - 1 {
|
||||
func.params[func.params.len - 1]
|
||||
} else {
|
||||
|
@ -1273,6 +1274,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
|||
}
|
||||
exp_arg_sym := c.table.sym(exp_arg_typ)
|
||||
c.expected_type = exp_arg_typ
|
||||
|
||||
mut got_arg_typ := c.check_expr_opt_call(arg.expr, c.expr(arg.expr))
|
||||
node.args[i].typ = got_arg_typ
|
||||
if no_type_promotion {
|
||||
|
|
Loading…
Reference in New Issue