From 00b9f0d76cc0e621c7dc3343cd3e9b047531191a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 11 Mar 2026 16:19:02 +0300 Subject: [PATCH] checker: builder error "This should never happen" (fixes #12434) --- vlib/v/ast/cflags.v | 3 +++ vlib/v/ast/cflags_test.v | 1 + vlib/v/checker/tests/hash_flag_backticks_err.out | 5 +++++ vlib/v/checker/tests/hash_flag_backticks_err.vv | 3 +++ 4 files changed, 12 insertions(+) create mode 100644 vlib/v/checker/tests/hash_flag_backticks_err.out create mode 100644 vlib/v/checker/tests/hash_flag_backticks_err.vv diff --git a/vlib/v/ast/cflags.v b/vlib/v/ast/cflags.v index 413b7ec7c..fe7a65c85 100644 --- a/vlib/v/ast/cflags.v +++ b/vlib/v/ast/cflags.v @@ -24,6 +24,9 @@ pub fn (mut t Table) parse_cflag(cflg string, mod string, ctimedefines []string) if flag == '' { return error('flag is empty') } + if flag.contains('`') { + return error('bad #flag `${flag_orig}`: shell command substitution with backticks is not supported; use #pkgconfig or explicit flags instead') + } mut fos := '' mut allowed_os_overrides := []string{} allowed_os_overrides << valid_comptime_not_user_defined diff --git a/vlib/v/ast/cflags_test.v b/vlib/v/ast/cflags_test.v index 1fa98de9a..cc80d4330 100644 --- a/vlib/v/ast/cflags_test.v +++ b/vlib/v/ast/cflags_test.v @@ -52,6 +52,7 @@ fn test_parse_invalid_cflags() { assert_parse_invalid_flag(mut t, 'windows -l') assert_parse_invalid_flag(mut t, '-I') assert_parse_invalid_flag(mut t, '-L') + assert_parse_invalid_flag(mut t, 'darwin `sdl2-config --cflags --libs` -lSDL2') // OS/compiler name only is not allowed assert_parse_invalid_flag(mut t, 'darwin') assert_parse_invalid_flag(mut t, 'freebsd') diff --git a/vlib/v/checker/tests/hash_flag_backticks_err.out b/vlib/v/checker/tests/hash_flag_backticks_err.out new file mode 100644 index 000000000..64ba4d655 --- /dev/null +++ b/vlib/v/checker/tests/hash_flag_backticks_err.out @@ -0,0 +1,5 @@ +vlib/v/checker/tests/hash_flag_backticks_err.vv:1:1: error: bad #flag `darwin `sdl2-config --cflags --libs` -lSDL2`: shell command substitution with backticks is not supported; use #pkgconfig or explicit flags instead + 1 | #flag darwin `sdl2-config --cflags --libs` -lSDL2 + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 2 | + 3 | fn main() {} diff --git a/vlib/v/checker/tests/hash_flag_backticks_err.vv b/vlib/v/checker/tests/hash_flag_backticks_err.vv new file mode 100644 index 000000000..3842e58ca --- /dev/null +++ b/vlib/v/checker/tests/hash_flag_backticks_err.vv @@ -0,0 +1,3 @@ +#flag darwin `sdl2-config --cflags --libs` -lSDL2 + +fn main() {} -- 2.39.5