From c304a95f11948a5281fed28bc2416a7da0980c21 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 30 Sep 2024 07:44:39 -0300 Subject: [PATCH] fix --- vlib/v/gen/c/cgen.v | 3 ++- vlib/v/tests/consts/const_c_string_test.v | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/consts/const_c_string_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index c278393be48b52..0e15b0cc1008d6 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5953,9 +5953,10 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) { } ast.StringLiteral { val := g.expr_string(field.expr) + typ := if field.expr.language == .c { 'char*' } else { 'string' } g.global_const_defs[util.no_dots(field.name)] = GlobalConstDef{ mod: field.mod - def: 'string ${const_name}; // a string literal, inited later' + def: '${typ} ${const_name}; // a string literal, inited later' init: '\t${const_name} = ${val};' order: -1 } diff --git a/vlib/v/tests/consts/const_c_string_test.v b/vlib/v/tests/consts/const_c_string_test.v new file mode 100644 index 00000000000000..bf904de0129016 --- /dev/null +++ b/vlib/v/tests/consts/const_c_string_test.v @@ -0,0 +1,7 @@ +const msg = c'test' + +fn test_main() { + unsafe { + assert msg.vstring() == 'test' + } +}