checker: bring back automatic c'foo' in c calls
parent
5e394f911f
commit
7b7602a2f9
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue