cgen: fix codegen for fn fixed array param w/ size defined by const (fix #22811) (#22812)

This commit is contained in:
Felipe Pena 2024-11-09 08:28:19 -03:00 committed by GitHub
parent bf8ea4b594
commit 6ffc9c94b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -272,6 +272,14 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
c.error('result type arguments are not supported', param.type_pos)
}
arg_typ_sym := c.table.sym(param.typ)
// resolve unresolved fixed array size e.g. [mod.const]array_type
if arg_typ_sym.info is ast.ArrayFixed
&& c.array_fixed_has_unresolved_size(arg_typ_sym.info) {
mut size_expr := unsafe { arg_typ_sym.info.size_expr }
param.typ = c.eval_array_fixed_sizes(mut size_expr, 0, arg_typ_sym.info.elem_type)
mut v := node.scope.find_var(param.name) or { continue }
v.typ = param.typ
}
if arg_typ_sym.info is ast.Struct {
if !param.typ.is_ptr() && arg_typ_sym.info.is_heap { // set auto_heap to promote value parameter
mut v := node.scope.find_var(param.name) or { continue }

View File

@ -0,0 +1,12 @@
module main
import crypto.ed25519
fn new_client_hello(public_key [ed25519.public_key_size]u8) {
assert public_key.len == ed25519.public_key_size
assert public_key.len != 0
}
fn test_main() {
new_client_hello([ed25519.public_key_size]u8{})
}