diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 74838a5643..dda2e53936 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -34,8 +34,10 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, && got.idx() in [ast.int_type_idx, ast.int_literal_type_idx]) { return } + // allow `C.printf('foo')` instead of `C.printf(c'foo')` if got.idx() == ast.string_type_idx - && expected in [ast.byteptr_type_idx, ast.charptr_type_idx] { + && (expected in [ast.byteptr_type_idx, ast.charptr_type_idx] + || (expected.idx() == ast.char_type_idx && expected.is_ptr())) { return } exp_sym := c.table.get_type_symbol(expected) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 483120ae67..b7093aae36 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -4268,7 +4268,8 @@ pub fn (mut c Checker) expr(node ast.Expr) ast.Type { } ast.StringLiteral { if node.language == .c { - return ast.byteptr_type + // string literal starts with "c": `C.printf(c'hello')` + return ast.byte_type.set_nr_muls(1) } return ast.string_type }