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:
parent
3c23a7ebba
commit
0ba0fb256f
@ -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
|
||||
|
4
vlib/v/checker/tests/sizeof.out
Normal file
4
vlib/v/checker/tests/sizeof.out
Normal file
@ -0,0 +1,4 @@
|
||||
vlib/v/checker/tests/sizeof.vv:1:13: error: unknown type `BadType`
|
||||
1 | x := sizeof(BadType)
|
||||
| ~~~~~~~
|
||||
2 | println(x)
|
2
vlib/v/checker/tests/sizeof.vv
Normal file
2
vlib/v/checker/tests/sizeof.vv
Normal file
@ -0,0 +1,2 @@
|
||||
x := sizeof(BadType)
|
||||
println(x)
|
@ -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]()}')
|
||||
|
Loading…
Reference in New Issue
Block a user