diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 5046ac9f5a..2aa05a7fa7 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1116,7 +1116,7 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type { if f.is_deprecated { c.warn('function `$f.name` has been deprecated', call_expr.pos) } - if f.is_generic { + if f.is_generic && f.return_type.has_flag(.generic) { rts := c.table.get_type_symbol(f.return_type) if rts.kind == .struct_ { rts_info := rts.info as table.Struct diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index e2b9082f76..d58cefd0d1 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1785,14 +1785,15 @@ fn (mut g Gen) expr(node ast.Expr) { } ast.SizeOf { if node.is_type { + node_typ := g.unwrap_generic(node.typ) mut styp := node.type_name if styp.starts_with('C.') { styp = styp[2..] } - if node.type_name == '' { - styp = g.typ(node.typ) + if node.type_name == '' || node.typ.has_flag(.generic) { + styp = g.typ(node_typ) } else { - sym := g.table.get_type_symbol(node.typ) + sym := g.table.get_type_symbol(node_typ) if sym.kind == .struct_ { info := sym.info as table.Struct if !info.is_typedef { diff --git a/vlib/v/tests/sizeof_2_test.v b/vlib/v/tests/sizeof_2_test.v new file mode 100644 index 0000000000..1e656b15f4 --- /dev/null +++ b/vlib/v/tests/sizeof_2_test.v @@ -0,0 +1,8 @@ +fn getsize

() u32 { + return sizeof(P) +} + +fn test_sizeof_2() { + assert getsize() == 8 + assert 4 == getsize() +}