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

checker: use .clear_flags() when comparing number literals

This commit is contained in:
Delyan Angelov 2021-04-05 10:39:48 +03:00
parent 9fcdf33501
commit 7a9607b028
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -140,12 +140,12 @@ pub fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool {
return true
}
// allow `return 0` in a function with `?int` return type
expected_nonopt := expected.clear_flag(.optional)
if got == ast.int_literal_type && expected_nonopt.is_int() {
expected_nonflagged := expected.clear_flags()
if got == ast.int_literal_type && expected_nonflagged.is_int() {
return true
}
// allow `return 0` in a function with `?f32` return type
if got == ast.float_literal_type && expected_nonopt.is_float() {
if got == ast.float_literal_type && expected_nonflagged.is_float() {
return true
}
return false