From 7029e39088f3a5672d5e750de70c92288ee80d38 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 21 Jul 2022 15:33:34 +0800 Subject: [PATCH] checker: check struct field with default expression (#15151) --- vlib/v/checker/struct.v | 2 +- vlib/v/checker/tests/struct_field_with_default_err.out | 6 ++++++ vlib/v/checker/tests/struct_field_with_default_err.vv | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/struct_field_with_default_err.out create mode 100644 vlib/v/checker/tests/struct_field_with_default_err.vv diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 40f298be5d..49eaa9705c 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -320,7 +320,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type { } if type_sym.name.len == 1 && !isnil(c.table.cur_fn) && c.table.cur_fn.generic_names.len == 0 { c.error('unknown struct `$type_sym.name`', node.pos) - return 0 + return ast.void_type } match type_sym.kind { .placeholder { diff --git a/vlib/v/checker/tests/struct_field_with_default_err.out b/vlib/v/checker/tests/struct_field_with_default_err.out new file mode 100644 index 0000000000..572f0eac3c --- /dev/null +++ b/vlib/v/checker/tests/struct_field_with_default_err.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/struct_field_with_default_err.vv:2:22: error: unknown struct `T` + 1 | struct Dummy { + 2 | arbitrary_field T = T{} + | ~~~ + 3 | } + 4 | diff --git a/vlib/v/checker/tests/struct_field_with_default_err.vv b/vlib/v/checker/tests/struct_field_with_default_err.vv new file mode 100644 index 0000000000..5bd78a829d --- /dev/null +++ b/vlib/v/checker/tests/struct_field_with_default_err.vv @@ -0,0 +1,5 @@ +struct Dummy { + arbitrary_field T = T{} +} + +fn main() {}