diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 6c7a15bfda..978d5bfc01 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -149,6 +149,10 @@ fn (mut c Checker) check_shift(left_type, right_type table.Type, left_pos, right if sym.kind == .alias && (sym.info as table.Alias).parent_type.is_int() { return left_type } + if c.pref.translated && left_type == table.bool_type { + // allow `bool << 2` in translated C code + return table.int_type + } c.error('invalid operation: shift of type `$sym.name`', left_pos) return table.void_type } else if !right_type.is_int() { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b509d9a1ac..5907e102a7 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1731,6 +1731,7 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) { } if c.pref.translated { // TODO fix this in C2V instead, for example cast enums to int before using `|` on them. + // TODO replace all c.pref.translated checks with `$if !translated` for performance continue } // Single side check @@ -3135,6 +3136,11 @@ pub fn (mut c Checker) enum_val(mut node ast.EnumVal) table.Type { return table.void_type } mut typ := table.new_type(typ_idx) + if c.pref.translated { + // TODO make more strict + node.typ = typ + return typ + } if typ == table.void_type { c.error('not an enum', node.pos) return table.void_type @@ -3146,7 +3152,8 @@ pub fn (mut c Checker) enum_val(mut node ast.EnumVal) table.Type { typ = array_info.elem_type typ_sym = c.table.get_type_symbol(typ) } - if typ_sym.kind != .enum_ { + if typ_sym.kind != .enum_ && !c.pref.translated { + // TODO in C int fields can be compared to enums, need to handle that in C2V c.error('expected type is not an enum (`$typ_sym.name`)', node.pos) return table.void_type } @@ -3220,6 +3227,10 @@ pub fn (mut c Checker) warn(s string, pos token.Position) { } pub fn (mut c Checker) error(message string, pos token.Position) { + if c.pref.translated && message.starts_with('mismatched types') { + // TODO move this + return + } if c.pref.is_verbose { print_backtrace() } diff --git a/vlib/v/checker/tests/match_expr_else.vv b/vlib/v/checker/tests/match_expr_else.vv index 7c5551e2e1..e31e7199e9 100644 --- a/vlib/v/checker/tests/match_expr_else.vv +++ b/vlib/v/checker/tests/match_expr_else.vv @@ -31,11 +31,11 @@ fn main() { string { 'string' } - else { - 'else' - } f64 { 'f64' } + else { + 'else' + } } } diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 93b6685897..cf3f781572 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -559,6 +559,9 @@ fn (mut p Parser) check_fn_atomic_arguments(typ table.Type, pos token.Position) } fn (mut p Parser) fn_redefinition_error(name string) { + if p.pref.translated { + return + } // Find where this function was already declared // TODO /*