From ea3b9ebb31de9f75c1785fe462eeba71bd44bba3 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 26 Feb 2026 10:03:12 +0300 Subject: [PATCH] checker: add error test for Result type in struct init fields (fixes #18210) --- .../crystallib_struct_init_result_err.out | 7 +++++++ .../crystallib_struct_init_result_err.vv | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 vlib/v/checker/tests/crystallib_struct_init_result_err.out create mode 100644 vlib/v/checker/tests/crystallib_struct_init_result_err.vv diff --git a/vlib/v/checker/tests/crystallib_struct_init_result_err.out b/vlib/v/checker/tests/crystallib_struct_init_result_err.out new file mode 100644 index 000000000..435668a8a --- /dev/null +++ b/vlib/v/checker/tests/crystallib_struct_init_result_err.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/crystallib_struct_init_result_err.vv:16:12: error: get_file() returns `!Path`, so it should have either an `or {}` block, or `!` at the end + 14 | mut doc := Doc{ + 15 | content: 'this is a first line.' + 16 | path: get_file('config.md', true) + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 17 | } + 18 | println('First println\n' + doc.content + '\n') diff --git a/vlib/v/checker/tests/crystallib_struct_init_result_err.vv b/vlib/v/checker/tests/crystallib_struct_init_result_err.vv new file mode 100644 index 000000000..c60055d74 --- /dev/null +++ b/vlib/v/checker/tests/crystallib_struct_init_result_err.vv @@ -0,0 +1,21 @@ +struct Path {} + +struct Doc { +mut: + content string + path Path +} + +fn get_file(path string, create bool) !Path { + return Path{} +} + +fn main() { + mut doc := Doc{ + content: 'this is a first line.' + path: get_file('config.md', true) + } + println('First println\n' + doc.content + '\n') + doc.content += '\nthis is a second line.' + println('Second println\n' + doc.content) +} -- 2.39.5