1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tests: fix a match test

This commit is contained in:
Alexander Medvednikov 2020-08-11 16:26:49 +02:00
parent 12d66208b8
commit c5aa2bfa51
4 changed files with 22 additions and 4 deletions

View File

@ -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() { if sym.kind == .alias && (sym.info as table.Alias).parent_type.is_int() {
return left_type 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) c.error('invalid operation: shift of type `$sym.name`', left_pos)
return table.void_type return table.void_type
} else if !right_type.is_int() { } else if !right_type.is_int() {

View File

@ -1731,6 +1731,7 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
} }
if c.pref.translated { if c.pref.translated {
// TODO fix this in C2V instead, for example cast enums to int before using `|` on them. // 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 continue
} }
// Single side check // Single side check
@ -3135,6 +3136,11 @@ pub fn (mut c Checker) enum_val(mut node ast.EnumVal) table.Type {
return table.void_type return table.void_type
} }
mut typ := table.new_type(typ_idx) 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 { if typ == table.void_type {
c.error('not an enum', node.pos) c.error('not an enum', node.pos)
return table.void_type 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 = array_info.elem_type
typ_sym = c.table.get_type_symbol(typ) 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) c.error('expected type is not an enum (`$typ_sym.name`)', node.pos)
return table.void_type 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) { 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 { if c.pref.is_verbose {
print_backtrace() print_backtrace()
} }

View File

@ -31,11 +31,11 @@ fn main() {
string { string {
'string' 'string'
} }
else {
'else'
}
f64 { f64 {
'f64' 'f64'
} }
else {
'else'
}
} }
} }

View File

@ -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) { fn (mut p Parser) fn_redefinition_error(name string) {
if p.pref.translated {
return
}
// Find where this function was already declared // Find where this function was already declared
// TODO // TODO
/* /*