diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index ba3152effc..34d3a74483 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -7,6 +7,9 @@ import v.ast import v.token pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, language ast.Language, arg ast.CallArg) ? { + if got == 0 { + return error('unexpected 0 type') + } mut expected := expected_ // variadic if expected.has_flag(.variadic) { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 947ca95640..1691a45c2a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -7605,8 +7605,14 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type { node.value_type = info.value_type return node.typ } else { - c.error('invalid empty map initilization syntax, use e.g. map[string]int{} instead', - node.pos) + if sym.kind == .struct_ { + c.error('`{}` can not be used for initialising empty structs any more. Use `${c.table.type_to_str(c.expected_type)}{}` instead.', + node.pos) + } else { + c.error('invalid empty map initialisation syntax, use e.g. map[string]int{} instead', + node.pos) + } + return ast.void_type } } // `x := map[string]string` - set in parser diff --git a/vlib/v/checker/tests/assign_to_typeless_variable_err.out b/vlib/v/checker/tests/assign_to_typeless_variable_err.out index 63599beb5f..5ce01263e9 100644 --- a/vlib/v/checker/tests/assign_to_typeless_variable_err.out +++ b/vlib/v/checker/tests/assign_to_typeless_variable_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/assign_to_typeless_variable_err.vv:2:10: error: invalid empty map initilization syntax, use e.g. map[string]int{} instead +vlib/v/checker/tests/assign_to_typeless_variable_err.vv:2:10: error: invalid empty map initialisation syntax, use e.g. map[string]int{} instead 1 | fn main() { 2 | val := {} | ~~ diff --git a/vlib/v/checker/tests/map_init_invalid_syntax.out b/vlib/v/checker/tests/map_init_invalid_syntax.out index c7fec6d947..49a0909cb6 100644 --- a/vlib/v/checker/tests/map_init_invalid_syntax.out +++ b/vlib/v/checker/tests/map_init_invalid_syntax.out @@ -1,6 +1,12 @@ -vlib/v/checker/tests/map_init_invalid_syntax.vv:2:7: error: invalid empty map initilization syntax, use e.g. map[string]int{} instead +vlib/v/checker/tests/map_init_invalid_syntax.vv:2:7: error: invalid empty map initialisation syntax, use e.g. map[string]int{} instead 1 | fn main() { 2 | a := {} | ~~ 3 | println(a) - 4 | } \ No newline at end of file + 4 | } +vlib/v/checker/tests/map_init_invalid_syntax.vv:3:2: error: `println` can not print void expressions + 1 | fn main() { + 2 | a := {} + 3 | println(a) + | ~~~~~~~~~~ + 4 | } diff --git a/vlib/v/checker/tests/method_call_with_empty_struct_init.out b/vlib/v/checker/tests/method_call_with_empty_struct_init.out new file mode 100644 index 0000000000..c8d98ed7db --- /dev/null +++ b/vlib/v/checker/tests/method_call_with_empty_struct_init.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/method_call_with_empty_struct_init.vv:10:11: error: `{}` can not be used for initialising empty structs any more. Use `Abc{}` instead. + 8 | fn main() { + 9 | s := Abc{} + 10 | s.abc(0, {}) + | ~~ + 11 | } diff --git a/vlib/v/checker/tests/method_call_with_empty_struct_init.vv b/vlib/v/checker/tests/method_call_with_empty_struct_init.vv new file mode 100644 index 0000000000..ca086f49a3 --- /dev/null +++ b/vlib/v/checker/tests/method_call_with_empty_struct_init.vv @@ -0,0 +1,11 @@ +struct Abc { + x int +} + +fn (s Abc) abc(x int, param Abc) { +} + +fn main() { + s := Abc{} + s.abc(0, {}) +}