mirror of
https://github.com/vlang/v.git
synced 2025-09-18 20:07:02 -04:00
cgen: fix code generated for or-block for void result return function + code generated for indirection comptime checking for logical operators (#18066)
This commit is contained in:
parent
ee9cfb6df4
commit
9fb52c4c9c
@ -717,18 +717,7 @@ fn (mut c Checker) comptime_if_branch(cond ast.Expr, pos token.Pos) ComptimeBran
|
|||||||
if c.is_comptime_selector_field_name(cond.left as ast.SelectorExpr,
|
if c.is_comptime_selector_field_name(cond.left as ast.SelectorExpr,
|
||||||
'indirections')
|
'indirections')
|
||||||
{
|
{
|
||||||
ret := match cond.op {
|
return .unknown
|
||||||
.gt { c.comptime_fields_default_type.nr_muls() > cond.right.val.i64() }
|
|
||||||
.lt { c.comptime_fields_default_type.nr_muls() < cond.right.val.i64() }
|
|
||||||
.ge { c.comptime_fields_default_type.nr_muls() >= cond.right.val.i64() }
|
|
||||||
.le { c.comptime_fields_default_type.nr_muls() <= cond.right.val.i64() }
|
|
||||||
else { false }
|
|
||||||
}
|
|
||||||
return if ret {
|
|
||||||
ComptimeBranchSkipState.eval
|
|
||||||
} else {
|
|
||||||
ComptimeBranchSkipState.skip
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.error('invalid `\$if` condition', cond.pos)
|
c.error('invalid `\$if` condition', cond.pos)
|
||||||
|
@ -5823,6 +5823,14 @@ fn (mut g Gen) gen_or_block_stmts(cvar_name string, cast_typ string, stmts []ast
|
|||||||
g.write('${cvar_name} = ')
|
g.write('${cvar_name} = ')
|
||||||
g.gen_option_error(return_type, expr_stmt.expr)
|
g.gen_option_error(return_type, expr_stmt.expr)
|
||||||
g.writeln(';')
|
g.writeln(';')
|
||||||
|
} else if return_type == ast.rvoid_type {
|
||||||
|
// fn returns !, do not fill var.data
|
||||||
|
old_inside_opt_data := g.inside_opt_data
|
||||||
|
g.inside_opt_data = true
|
||||||
|
g.expr(expr_stmt.expr)
|
||||||
|
g.inside_opt_data = old_inside_opt_data
|
||||||
|
g.writeln(';')
|
||||||
|
g.stmt_path_pos.delete_last()
|
||||||
} else {
|
} else {
|
||||||
if is_option {
|
if is_option {
|
||||||
g.write('*(${cast_typ}*) ${cvar_name}.data = ')
|
g.write('*(${cast_typ}*) ${cvar_name}.data = ')
|
||||||
|
5
vlib/v/slow_tests/inout/or_block_with_rvoid.out
Normal file
5
vlib/v/slow_tests/inout/or_block_with_rvoid.out
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
aaaaaaaaaaaaaaaaaaaa
|
||||||
|
aaaaaaaaaaaaaaaaaaaa
|
||||||
|
aaaaaaaaaaaaaaaaaaaa
|
||||||
|
aaaaaaaaaaaaaaaaaaaa
|
||||||
|
aaaaaaaaaaaaaaaaaaaa
|
65
vlib/v/slow_tests/inout/or_block_with_rvoid.vv
Normal file
65
vlib/v/slow_tests/inout/or_block_with_rvoid.vv
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
struct Encoder {}
|
||||||
|
|
||||||
|
struct Writer {}
|
||||||
|
|
||||||
|
struct StructTypePointer[T] {
|
||||||
|
mut:
|
||||||
|
val &T
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Null {
|
||||||
|
is_null bool = true
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const null = Null{}
|
||||||
|
|
||||||
|
pub fn (e &Encoder) encode_value[T](val T, mut wr Writer) ! {
|
||||||
|
e.encode_struct[T](val, 1, mut wr)!
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (e &Encoder) encode_struct[U](val U, level int, mut wr Writer) ! {
|
||||||
|
$for field in U.fields {
|
||||||
|
$if field.indirections > 0 {
|
||||||
|
println('aaaaaaaaaaaaaaaaaaaa')
|
||||||
|
} $else {
|
||||||
|
println('bbbbbbbbbbbbbbbbbbbb')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
e := Encoder{}
|
||||||
|
|
||||||
|
mut sb := Writer{}
|
||||||
|
mut string_initialized_with_reference := 'ads'
|
||||||
|
|
||||||
|
e.encode_value(StructTypePointer[string]{ val: &string_initialized_with_reference }, mut
|
||||||
|
sb) or {
|
||||||
|
println(err)
|
||||||
|
e.encode_value[Null](null, mut sb) or {}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.encode_value(StructTypePointer[string]{ val: &string_initialized_with_reference }, mut
|
||||||
|
sb) or {
|
||||||
|
println(err)
|
||||||
|
e.encode_value[Null](null, mut sb) or {}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.encode_value(StructTypePointer[string]{ val: &string_initialized_with_reference }, mut
|
||||||
|
sb) or {
|
||||||
|
println(err)
|
||||||
|
e.encode_value[Null](null, mut sb) or {}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.encode_value(StructTypePointer[string]{ val: &string_initialized_with_reference }, mut
|
||||||
|
sb) or {
|
||||||
|
dump(err)
|
||||||
|
e.encode_value[Null](null, mut sb) or {}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.encode_value(StructTypePointer[string]{ val: &string_initialized_with_reference }, mut
|
||||||
|
sb) or {
|
||||||
|
dump(err)
|
||||||
|
e.encode_value[Null](null, mut sb) or {}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user