diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index e5daa0e4e2..f52d471491 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2629,6 +2629,11 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type { if !node.is_type { node.typ = c.expr(node.expr) } + sym := c.table.final_sym(node.typ) + if sym.kind == .placeholder && sym.language != .c { + // Allow `sizeof(C.MYSQL_TIME)` etc + c.error('unknown type `${sym.name}`', node.pos) + } // c.deprecate_old_isreftype_and_sizeof_of_a_guessed_type(node.guessed_type, // node.typ, node.pos, 'sizeof') return ast.u32_type diff --git a/vlib/v/checker/tests/sizeof.out b/vlib/v/checker/tests/sizeof.out new file mode 100644 index 0000000000..639cc246c8 --- /dev/null +++ b/vlib/v/checker/tests/sizeof.out @@ -0,0 +1,4 @@ +vlib/v/checker/tests/sizeof.vv:1:13: error: unknown type `BadType` + 1 | x := sizeof(BadType) + | ~~~~~~~ + 2 | println(x) diff --git a/vlib/v/checker/tests/sizeof.vv b/vlib/v/checker/tests/sizeof.vv new file mode 100644 index 0000000000..47bacda256 --- /dev/null +++ b/vlib/v/checker/tests/sizeof.vv @@ -0,0 +1,2 @@ +x := sizeof(BadType) +println(x) diff --git a/vlib/v/checker/tests/unknown_sizeof_type_err_b.out b/vlib/v/checker/tests/unknown_sizeof_type_err_b.out index f6c51c4444..7ab8a395b0 100644 --- a/vlib/v/checker/tests/unknown_sizeof_type_err_b.out +++ b/vlib/v/checker/tests/unknown_sizeof_type_err_b.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/unknown_sizeof_type_err_b.vv:14:34: cgen error: unknown type `Zabc` +vlib/v/checker/tests/unknown_sizeof_type_err_b.vv:14:34: error: unknown type `Zabc` 12 | println('size of Abc: ${sizeof[Abc]()}') 13 | println('size of Xyz: ${sizeof[Xyz]()}') 14 | println('size of Test: ${sizeof[Zabc]()}')