From abc143271747ac64d663177e5744a176a2f88be8 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 28 Sep 2024 11:22:38 +0300 Subject: [PATCH] cgen: add `asm` to c_reserved, fixes compilation of `struct Abc { @asm int }` --- vlib/v/gen/c/cgen.v | 14 ++++++------- vlib/v/tests/reserved_keyword_asm_test.v | 26 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 vlib/v/tests/reserved_keyword_asm_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 23ea0a91badf44..9d57ed19587931 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -20,13 +20,13 @@ import sync.pool // in C++, or have special meaning in V, thus need escaping too. `small` // should not be needed, but see: // https://stackoverflow.com/questions/5874215/what-is-rpcndr-h -const c_reserved = ['array', 'auto', 'bool', 'break', 'calloc', 'case', 'char', 'class', 'complex', - 'const', 'continue', 'default', 'delete', 'do', 'double', 'else', 'enum', 'error', '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'] +const c_reserved = ['asm', 'array', 'auto', 'bool', 'break', 'calloc', 'case', 'char', 'class', + 'complex', 'const', 'continue', 'default', 'delete', 'do', 'double', 'else', 'enum', 'error', + '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'] 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/reserved_keyword_asm_test.v b/vlib/v/tests/reserved_keyword_asm_test.v new file mode 100644 index 00000000000000..805a1cbc6f914f --- /dev/null +++ b/vlib/v/tests/reserved_keyword_asm_test.v @@ -0,0 +1,26 @@ +struct Abc { + @asm string +} + +enum Enum { + @asm + end +} + +fn test_struct() { + dump(Abc{}) + assert true +} + +fn test_local() { + @asm := 12 + dump(@asm) + assert true +} + +fn test_enum() { + dump(unsafe { Enum(0) }) + dump(Enum.@asm) + dump(Enum.end) + assert true +}