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

checker: fix cast to byte in comptime if (#13036)

This commit is contained in:
yuyi 2022-01-05 15:27:10 +08:00 committed by GitHub
parent 89ac2a37c5
commit ba9aad1d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -2629,7 +2629,7 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
// node.typ: `Outside`
node.expr_type = c.expr(node.expr) // type to be casted
mut from_type := node.expr_type
mut from_type := c.unwrap_generic(node.expr_type)
from_sym := c.table.sym(from_type)
final_from_sym := c.table.final_sym(from_type)

View File

@ -0,0 +1,18 @@
fn test_cast_in_comptime_if() {
generic_bool(true)
}
fn generic_bool<T>(val T) {
$if T is bool {
println(byte(val))
assert byte(val) == 1
println(i8(val))
assert i8(val) == 1
println(i16(val))
assert i16(val) == 1
} $else {
assert false
}
}