diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index e37dfe755b..d153683fb8 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1921,6 +1921,7 @@ fn (mut g Gen) expr(node ast.Expr) { // &Foo(0) => ((Foo*)0) g.out.go_back(1) } + g.is_amp = false sym := g.table.get_type_symbol(node.typ) if sym.kind == .string && !node.typ.is_ptr() { // `string(x)` needs `tos()`, but not `&string(x) @@ -1950,14 +1951,8 @@ fn (mut g Gen) expr(node ast.Expr) { g.expr(node.expr) g.write('))') } else { - // styp := g.table.Type_to_str(it.typ) styp := g.typ(node.typ) - // g.write('($styp)(') g.write('(($styp)(') - // if g.is_amp { - // g.write('*') - // } - // g.write(')(') g.expr(node.expr) if node.expr is ast.IntegerLiteral && node.typ in [table.u64_type, table.u32_type, table.u16_type] { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 62ecf52645..783660730f 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1061,6 +1061,10 @@ pub fn (mut p Parser) name_expr() ast.Expr { // Handle `&Foo(0)` to_typ = to_typ.to_ptr() } + // this prevents inner casts to also have an `&` + // example: &Foo(malloc(int(num))) + // without the next line int would result in int* + p.is_amp = false p.check(.lpar) mut expr := ast.Expr{} mut arg := ast.Expr{} diff --git a/vlib/v/parser/pratt.v b/vlib/v/parser/pratt.v index b4812722ac..8b9af1b129 100644 --- a/vlib/v/parser/pratt.v +++ b/vlib/v/parser/pratt.v @@ -340,7 +340,7 @@ fn (mut p Parser) prefix_expr() ast.PrefixExpr { p.next() mut right := if op == .minus { p.expr(token.Precedence.call) } else { p.expr(token.Precedence.prefix) } p.is_amp = false - if mut right is ast.CastExpr { + if right is ast.CastExpr { right.in_prexpr = true } mut or_stmts := []ast.Stmt{}