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

checker: handle if _likely_(x is Interface) { from #11485 (#11519)

This commit is contained in:
Alexander Ivanov 2021-09-17 21:01:12 +03:00 committed by GitHub
parent fb75d528eb
commit 30e53c95c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -6709,6 +6709,8 @@ fn (mut c Checker) smartcast_if_conds(node ast.Expr, mut scope ast.Scope) {
}
}
}
} else if node is ast.Likely {
c.smartcast_if_conds(node.expr, mut scope)
}
}

View File

@ -0,0 +1,17 @@
// fixes https://github.com/vlang/v/issues/11485 based on code example by https://github.com/Wertzui123
interface IExample {
}
struct Example {
value string
}
fn test_if_smartcast_likely() {
print_value(Example{ value: 'Hello' })
}
fn print_value(example IExample) {
if _likely_(example is Example) {
print('Value: ' + example.value)
}
}