From f5036629ca8044bf21faf57e22a7ee292334e83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?El=20Koulali=20Andr=C3=A1s?= <42486026+CoderCharmander@users.noreply.github.com> Date: Mon, 21 Mar 2022 10:00:30 +0100 Subject: [PATCH] cgen: add `true` and `false` to C reserved words (#13781) --- vlib/v/gen/c/cgen.v | 9 +++++---- vlib/v/tests/keyword_escaping_test.v | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 vlib/v/tests/keyword_escaping_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 171a65defb..b153eabcdd 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -20,10 +20,11 @@ const ( // `small` should not be needed, but see: https://stackoverflow.com/questions/5874215/what-is-rpcndr-h c_reserved = ['array', 'auto', 'bool', 'break', 'calloc', 'case', 'char', 'class', 'complex', 'const', 'continue', 'default', 'delete', 'do', 'double', 'else', 'enum', 'error', 'exit', - 'export', 'extern', 'float', 'for', 'free', 'goto', 'if', 'inline', 'int', 'link', 'long', - 'malloc', 'namespace', 'new', 'panic', 'register', 'restrict', 'return', 'short', 'signed', - 'sizeof', 'static', 'string', 'struct', 'switch', 'typedef', 'typename', 'union', 'unix', - 'unsigned', 'void', 'volatile', 'while', 'template', 'small', 'stdout', 'stdin', 'stderr'] + 'export', 'extern', 'false', 'float', 'for', 'free', 'goto', 'if', 'inline', 'int', 'link', + 'long', 'malloc', 'namespace', 'new', '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'] c_reserved_map = string_array_to_map(c_reserved) // same order as in token.Kind cmp_str = ['eq', 'ne', 'gt', 'lt', 'ge', 'le'] diff --git a/vlib/v/tests/keyword_escaping_test.v b/vlib/v/tests/keyword_escaping_test.v new file mode 100644 index 0000000000..c96c5e47d4 --- /dev/null +++ b/vlib/v/tests/keyword_escaping_test.v @@ -0,0 +1,11 @@ +fn test_escapes() { + @if := 0 + @for := 0 + auto := 0 + calloc := 0 + stdout := 0 + signed := 0 + @true := 0 + @false := 0 + assert true +}