mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix generic with fixed array parameter (#10233)
This commit is contained in:
parent
7089ff3957
commit
9ea753e853
@ -6453,19 +6453,32 @@ fn (mut c Checker) check_index(typ_sym &ast.TypeSymbol, index ast.Expr, index_ty
|
||||
|
||||
pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
|
||||
mut typ := c.expr(node.left)
|
||||
mut typ_sym := c.table.get_final_type_symbol(typ)
|
||||
node.left_type = typ
|
||||
typ_sym := c.table.get_final_type_symbol(typ)
|
||||
for {
|
||||
match typ_sym.kind {
|
||||
.map {
|
||||
node.is_map = true
|
||||
break
|
||||
}
|
||||
.array {
|
||||
node.is_array = true
|
||||
break
|
||||
}
|
||||
.array_fixed {
|
||||
node.is_farray = true
|
||||
break
|
||||
}
|
||||
.any {
|
||||
typ = c.unwrap_generic(typ)
|
||||
node.left_type = typ
|
||||
typ_sym = c.table.get_final_type_symbol(typ)
|
||||
continue
|
||||
}
|
||||
else {
|
||||
break
|
||||
}
|
||||
}
|
||||
else {}
|
||||
}
|
||||
if typ_sym.kind !in [.array, .array_fixed, .string, .map] && !typ.is_ptr()
|
||||
&& typ !in [ast.byteptr_type, ast.charptr_type] && !typ.has_flag(.variadic) {
|
||||
|
10
vlib/v/tests/generics_with_fixed_array_type_test.v
Normal file
10
vlib/v/tests/generics_with_fixed_array_type_test.v
Normal file
@ -0,0 +1,10 @@
|
||||
fn show_element<T>(arr &T) string {
|
||||
return unsafe { '${arr[1]}' }
|
||||
}
|
||||
|
||||
fn test_generic_with_fixed_array_type() {
|
||||
a := [1, 2, 3]!
|
||||
ret := show_element(a)
|
||||
println(ret)
|
||||
assert ret == '2'
|
||||
}
|
Loading…
Reference in New Issue
Block a user