From 505a247706d97c26bbf1c02936f8f04d234b4719 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 7 Nov 2024 17:43:39 +0800 Subject: [PATCH] cgen: fix struct field name using c keyword `typeof` (fix #22779) (#22782) --- vlib/v/gen/c/cgen.v | 4 ++-- .../structs/struct_field_name_using_c_keyword_test.v | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 vlib/v/tests/structs/struct_field_name_using_c_keyword_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 4ee62deb7..9f29f39a2 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -25,8 +25,8 @@ const c_reserved = ['asm', 'array', 'auto', 'bool', 'break', 'calloc', 'case', ' 'exit', 'export', 'extern', 'false', 'float', 'for', 'free', 'goto', 'if', 'inline', 'int', 'link', 'long', 'malloc', 'namespace', 'new', 'nil', 'panic', 'register', 'restrict', 'return', 'short', 'signed', 'sizeof', 'static', 'string', 'struct', 'switch', 'typedef', 'typename', - 'union', 'unix', 'unsigned', 'void', 'volatile', 'while', 'template', 'true', 'small', 'stdout', - 'stdin', 'stderr', 'far', 'near', 'huge', 'requires'] + 'typeof', 'union', 'unix', 'unsigned', 'void', 'volatile', 'while', 'template', 'true', 'small', + 'stdout', 'stdin', 'stderr', 'far', 'near', 'huge', 'requires'] const c_reserved_chk = token.new_keywords_matcher_from_array_trie(c_reserved) // same order as in token.Kind const cmp_str = ['eq', 'ne', 'gt', 'lt', 'ge', 'le'] diff --git a/vlib/v/tests/structs/struct_field_name_using_c_keyword_test.v b/vlib/v/tests/structs/struct_field_name_using_c_keyword_test.v new file mode 100644 index 000000000..82d10c005 --- /dev/null +++ b/vlib/v/tests/structs/struct_field_name_using_c_keyword_test.v @@ -0,0 +1,9 @@ +struct Keywords { + typeof u8 +} + +fn test_struct_field_name_using_c_reserved() { + key := Keywords{} + println(key) + assert true +} -- 2.39.5