checker: c2v fixes

pull/13217/head
Alexander Medvednikov 2022-01-19 15:26:24 +03:00
parent c48a9e71f5
commit 38d3239b50
4 changed files with 7 additions and 3 deletions

View File

@ -171,6 +171,9 @@ fn C.tolower(c int) int
[trusted]
fn C.toupper(c int) int
[trusted]
fn C.strchr(s &char, c int) &char
[trusted]
fn C.getchar() int

View File

@ -2704,7 +2704,8 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
}
}
}
} else if to_type == ast.bool_type && from_type != ast.bool_type && !c.inside_unsafe {
} else if to_type == ast.bool_type && from_type != ast.bool_type && !c.inside_unsafe
&& !c.pref.translated {
c.error('cannot cast to bool - use e.g. `some_int != 0` instead', node.pos)
} else if from_type == ast.none_type && !to_type.has_flag(.optional) {
type_name := c.table.type_to_str(to_type)

View File

@ -28,7 +28,7 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
mut is_comptime_type_is_expr := false // if `$if T is string`
for i in 0 .. node.branches.len {
mut branch := node.branches[i]
if branch.cond is ast.ParExpr {
if branch.cond is ast.ParExpr && !c.pref.translated {
c.error('unnecessary `()` in `$if_kind` condition, use `$if_kind expr {` instead of `$if_kind (expr) {`.',
branch.pos)
}

View File

@ -8,7 +8,7 @@ import strings
pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
node.is_expr = c.expected_type != ast.void_type
node.expected_type = c.expected_type
if node.cond is ast.ParExpr {
if node.cond is ast.ParExpr && !c.pref.translated {
c.error('unnecessary `()` in `match` condition, use `match expr {` instead of `match (expr) {`.',
node.cond.pos)
}