1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: check the type of SizeOf

This commit is contained in:
Alexander Medvednikov 2023-03-03 18:45:06 +01:00
parent 3c23a7ebba
commit 0ba0fb256f
4 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1,4 @@
vlib/v/checker/tests/sizeof.vv:1:13: error: unknown type `BadType`
1 | x := sizeof(BadType)
| ~~~~~~~
2 | println(x)

View File

@ -0,0 +1,2 @@
x := sizeof(BadType)
println(x)

View File

@ -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]()}')