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:
parent
89ac2a37c5
commit
ba9aad1d92
@ -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)
|
||||
|
||||
|
18
vlib/v/tests/cast_in_comptime_if_test.v
Normal file
18
vlib/v/tests/cast_in_comptime_if_test.v
Normal 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user