cgen: fix cast in the index of reference fixed array (fix #13128) (#13131)

pull/13136/head
yuyi 2022-01-11 16:55:29 +08:00 committed by GitHub
parent 078229f213
commit 1e52b2c134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -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)

View File

@ -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
}