Skip to content

Commit

Permalink
cgen: fix cast in the index of reference fixed array (fix #13128) (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Jan 11, 2022
1 parent 078229f commit 1e52b2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 0 additions & 5 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -4437,11 +4437,6 @@ fn (mut g Gen) ident(node ast.Ident) {
}

fn (mut g Gen) cast_expr(node ast.CastExpr) {
if g.is_amp {
// &Foo(0) => ((Foo*)0)
g.out.go_back(1)
}
g.is_amp = false
sym := g.table.sym(node.typ)
if sym.kind in [.sum_type, .interface_] {
g.expr_with_cast(node.expr, node.expr_type, node.typ)
Expand Down
16 changes: 16 additions & 0 deletions vlib/v/tests/cast_in_index_of_ref_fixed_array_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type Entity = int

struct Component {
vals [256]int
}

fn (c Component) get_broken(e Entity) &int {
return &c.vals[int(e)]
}

fn test_cast_in_ref_fixed_array() {
c := Component{}
a := c.get_broken(Entity(10))
println(*a)
assert *a == 0
}

0 comments on commit 1e52b2c

Please sign in to comment.