checker: bring back automatic c'foo' in c calls

pull/9608/head
Alexander Medvednikov 2021-04-05 06:36:02 +03:00
parent 5e394f911f
commit 7b7602a2f9
2 changed files with 5 additions and 2 deletions

View File

@ -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]) { && got.idx() in [ast.int_type_idx, ast.int_literal_type_idx]) {
return return
} }
// allow `C.printf('foo')` instead of `C.printf(c'foo')`
if got.idx() == ast.string_type_idx 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 return
} }
exp_sym := c.table.get_type_symbol(expected) exp_sym := c.table.get_type_symbol(expected)

View File

@ -4268,7 +4268,8 @@ pub fn (mut c Checker) expr(node ast.Expr) ast.Type {
} }
ast.StringLiteral { ast.StringLiteral {
if node.language == .c { 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 return ast.string_type
} }