checker: allow + - * on pointers for translated code (#14183)

playX 2022-04-26 18:00:44 +00:00 committed by Jef Roosens
parent 609464bc9c
commit c37bb48e9c
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 6 additions and 1 deletions

View File

@ -702,8 +702,13 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
&& c.table.sym((left_sym.info as ast.Alias).parent_type).is_primitive() { && c.table.sym((left_sym.info as ast.Alias).parent_type).is_primitive() {
left_sym = c.table.sym((left_sym.info as ast.Alias).parent_type) left_sym = c.table.sym((left_sym.info as ast.Alias).parent_type)
} }
if c.pref.translated && node.op in [.plus, .minus, .mul]
&& left_type.is_any_kind_of_pointer()
&& (right_type.is_any_kind_of_pointer() || right_type.is_int()) {
return_type = left_type
}
// Check if the alias type is not a primitive then allow using operator overloading for aliased `arrays` and `maps` // Check if the alias type is not a primitive then allow using operator overloading for aliased `arrays` and `maps`
if !c.pref.translated && left_sym.kind == .alias && left_sym.info is ast.Alias else 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()) { && !(c.table.sym((left_sym.info as ast.Alias).parent_type).is_primitive()) {
if left_sym.has_method(node.op.str()) { if left_sym.has_method(node.op.str()) {
if method := left_sym.find_method(node.op.str()) { if method := left_sym.find_method(node.op.str()) {