checker: c2v fixes (#14332)
parent
cb52c68a62
commit
1e83e10119
|
@ -22,7 +22,8 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
||||||
if expected == ast.voidptr_type {
|
if expected == ast.voidptr_type {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if expected == ast.bool_type && (got.is_any_kind_of_pointer() || got.is_int()) {
|
if (expected == ast.bool_type && (got.is_any_kind_of_pointer() || got.is_int()))
|
||||||
|
|| ((expected.is_any_kind_of_pointer() || expected.is_int()) && got == ast.bool_type) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,9 +51,7 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
||||||
}
|
}
|
||||||
} else if got_sym.kind == .array_fixed {
|
} else if got_sym.kind == .array_fixed {
|
||||||
// Allow fixed arrays as `&i8` etc
|
// Allow fixed arrays as `&i8` etc
|
||||||
if expected_sym.is_number() {
|
if expected_sym.is_number() || expected.is_any_kind_of_pointer() {
|
||||||
return true
|
|
||||||
} else if expected.is_any_kind_of_pointer() {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} else if expected_sym.kind == .array_fixed {
|
} else if expected_sym.kind == .array_fixed {
|
||||||
|
@ -65,6 +64,14 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if got_sym.kind == .array {
|
||||||
|
if expected_sym.is_number() || expected.is_any_kind_of_pointer() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else if expected_sym.kind == .array {
|
||||||
|
if got_sym.is_number() && got.is_any_kind_of_pointer() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if expected_sym.kind == .enum_ && got_sym.is_number() {
|
if expected_sym.kind == .enum_ && got_sym.is_number() {
|
||||||
// Allow enums as numbers
|
// Allow enums as numbers
|
||||||
|
|
|
@ -959,10 +959,10 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Allow `[32]i8` as `&i8` etc
|
// Allow `[32]i8` as `&i8` etc
|
||||||
if (arg_typ_sym.kind == .array_fixed && (param_is_number
|
if ((arg_typ_sym.kind == .array_fixed || arg_typ_sym.kind == .array)
|
||||||
|| param.typ.is_any_kind_of_pointer()))
|
&& (param_is_number || param.typ.is_any_kind_of_pointer()))
|
||||||
|| (param_typ_sym.kind == .array_fixed && (typ_is_number
|
|| ((param_typ_sym.kind == .array_fixed || param_typ_sym.kind == .array)
|
||||||
|| arg_typ.is_any_kind_of_pointer())) {
|
&& (typ_is_number || arg_typ.is_any_kind_of_pointer())) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Allow `int` as `&i8`
|
// Allow `int` as `&i8`
|
||||||
|
|
Loading…
Reference in New Issue