diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c6c0f73c8d..c72fa5d8a3 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1667,6 +1667,12 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { if sym.kind !in [.struct_, .aggregate, .interface_, .sum_type] { if sym.kind != .placeholder { unwrapped_sym := c.table.sym(c.unwrap_generic(typ)) + + if unwrapped_sym.kind == .array_fixed && node.field_name == 'len' { + node.typ = ast.int_type + return ast.int_type + } + c.error('`$unwrapped_sym.name` has no property `$node.field_name`', node.pos) } } else { diff --git a/vlib/v/tests/comptime_generic_test.v b/vlib/v/tests/comptime_generic_test.v new file mode 100644 index 0000000000..b19479e032 --- /dev/null +++ b/vlib/v/tests/comptime_generic_test.v @@ -0,0 +1,38 @@ +fn test_comptime_generic() { + a := [5]int{} + func1(&a) +} + +[inline] +pub fn func1(t &T) { + func2(t) +} + +[inline] +pub fn func2(t &T) { + $if T is $Array { + unsafe { + for i in 0 .. t.len { + func2(&t[i]) + } + } + } $else $if T is $Map { + // fake_map(t, df) + } $else $if T is $Struct { + $for f in T.fields { + $if f.typ is string { + } + // Dummy expression to generate and specify t.$(f.name)'s type + + // mut attrs := get_attrs(t.$(f.name), f) + + // if !attrs.skip() { + // fake_data_wdf(&(t.$(f.name))) + // } + } + } $else { + unsafe { + // *t = fake_primitive_value(df) or { panic(err) } + } + } +}