mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
c7a92425f0
commit
62553dcc2e
@ -190,10 +190,8 @@ fn (mut p Process) win_read_string(idx int, maxbytes int) (string, int) {
|
|||||||
return '', 0
|
return '', 0
|
||||||
}
|
}
|
||||||
mut bytes_avail := int(0)
|
mut bytes_avail := int(0)
|
||||||
unsafe {
|
if !C.PeekNamedPipe(rhandle, voidptr(0), int(0), voidptr(0), &bytes_avail, voidptr(0)) {
|
||||||
if C.PeekNamedPipe(rhandle, voidptr(0), int(0), voidptr(0), &bytes_avail, voidptr(0)) == false {
|
return '', 0
|
||||||
return '', 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if bytes_avail == 0 {
|
if bytes_avail == 0 {
|
||||||
return '', 0
|
return '', 0
|
||||||
|
@ -3771,6 +3771,11 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
|
|||||||
g.write('))')
|
g.write('))')
|
||||||
} else if sym.kind == .alias && g.table.final_sym(node.typ).kind == .array_fixed {
|
} else if sym.kind == .alias && g.table.final_sym(node.typ).kind == .array_fixed {
|
||||||
g.expr(node.expr)
|
g.expr(node.expr)
|
||||||
|
} else if node.expr_type == ast.bool_type && node.typ.is_int() {
|
||||||
|
styp := g.typ(node.typ)
|
||||||
|
g.write('($styp[]){(')
|
||||||
|
g.expr(node.expr)
|
||||||
|
g.write(')?1:0}[0]')
|
||||||
} else {
|
} else {
|
||||||
styp := g.typ(node.typ)
|
styp := g.typ(node.typ)
|
||||||
if (g.pref.translated || g.file.is_translated) && sym.kind == .function {
|
if (g.pref.translated || g.file.is_translated) && sym.kind == .function {
|
||||||
|
@ -120,7 +120,7 @@ fn (mut g Gen) sql_create_table(node ast.SqlStmtLine, expr string, table_name st
|
|||||||
}
|
}
|
||||||
g.write('.typ = $typ,')
|
g.write('.typ = $typ,')
|
||||||
g.write('.is_arr = ${sym.kind == .array}, ')
|
g.write('.is_arr = ${sym.kind == .array}, ')
|
||||||
g.write('.is_time = ${int(g.table.get_type_name(field.typ) == 'time__Time')},')
|
g.write('.is_time = ${g.table.get_type_name(field.typ) == 'time__Time'},')
|
||||||
g.write('.default_val = (string){.str = (byteptr) "$field.default_val", .is_lit = 1},')
|
g.write('.default_val = (string){.str = (byteptr) "$field.default_val", .is_lit = 1},')
|
||||||
g.write('.attrs = new_array_from_c_array($field.attrs.len, $field.attrs.len, sizeof(StructAttribute),')
|
g.write('.attrs = new_array_from_c_array($field.attrs.len, $field.attrs.len, sizeof(StructAttribute),')
|
||||||
if field.attrs.len > 0 {
|
if field.attrs.len > 0 {
|
||||||
@ -128,7 +128,7 @@ fn (mut g Gen) sql_create_table(node ast.SqlStmtLine, expr string, table_name st
|
|||||||
for attr in field.attrs {
|
for attr in field.attrs {
|
||||||
g.write('(StructAttribute){')
|
g.write('(StructAttribute){')
|
||||||
g.write('.name = _SLIT("$attr.name"),')
|
g.write('.name = _SLIT("$attr.name"),')
|
||||||
g.write('.has_arg = ${int(attr.has_arg)},')
|
g.write('.has_arg = $attr.has_arg,')
|
||||||
g.write('.arg = _SLIT("$attr.arg"),')
|
g.write('.arg = _SLIT("$attr.arg"),')
|
||||||
g.write('.kind = ${int(attr.kind)},')
|
g.write('.kind = ${int(attr.kind)},')
|
||||||
g.write('},')
|
g.write('},')
|
||||||
|
12
vlib/v/tests/cast_bool_to_int_test.v
Normal file
12
vlib/v/tests/cast_bool_to_int_test.v
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
fn test_cast_bool_to_int() {
|
||||||
|
i := true
|
||||||
|
a := [1, 2, 3]
|
||||||
|
|
||||||
|
println(a[int(!i)])
|
||||||
|
assert a[int(!i)] == 1
|
||||||
|
|
||||||
|
println(a[int(i)])
|
||||||
|
assert a[int(i)] == 2
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user