Skip to content

Commit

Permalink
builtin, cgen: improve the assert informations
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Oct 27, 2024
1 parent 14b1a14 commit b219038
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion vlib/builtin/builtin.v
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ pub fn (ami &VAssertMetaInfo) free() {
fn __print_assert_failure(i &VAssertMetaInfo) {
eprintln('${i.fpath}:${i.line_nr + 1}: FAIL: fn ${i.fn_name}: assert ${i.src}')
if i.op.len > 0 && i.op != 'call' {
eprintln(' left value: ${i.llabel} = ${i.lvalue}')
if i.llabel == i.lvalue {
eprintln(' left value: ${i.llabel}')
} else {
eprintln(' left value: ${i.llabel} = ${i.lvalue}')
}
if i.rlabel == i.rvalue {
eprintln(' right value: ${i.rlabel}')
} else {
Expand Down
10 changes: 5 additions & 5 deletions vlib/v/gen/c/assert.v
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,21 @@ fn (mut g Gen) gen_assert_metainfo(node ast.AssertStmt, kind AssertMetainfoKind)

fn (mut g Gen) gen_assert_single_expr(expr ast.Expr, typ ast.Type) {
// eprintln('> gen_assert_single_expr typ: $typ | expr: $expr | typeof(expr): ${typeof(expr)}')
unknown_value := '*unknown value*'
expr_str := '${expr}'
match expr {
ast.CastExpr {
if typ.is_float() || g.table.final_sym(typ).is_float() {
g.gen_expr_to_string(expr.expr, typ)
} else {
g.write(ctoslit(unknown_value))
g.write(ctoslit(expr_str))
}
}
ast.IfExpr, ast.MatchExpr {
g.write(ctoslit(unknown_value))
g.write(ctoslit(expr_str))
}
ast.IndexExpr {
if expr.index is ast.RangeExpr {
g.write(ctoslit(unknown_value))
g.write(ctoslit(expr_str))
} else {
g.gen_expr_to_string(expr, typ)
}
Expand All @@ -203,7 +203,7 @@ fn (mut g Gen) gen_assert_single_expr(expr ast.Expr, typ ast.Type) {
// TODO: remove this check;
// vlib/builtin/map_test.v (a map of &int, set to &int(0)) fails
// without special casing ast.CastExpr here
g.write(ctoslit(unknown_value))
g.write(ctoslit(expr_str))
} else {
g.gen_expr_to_string(expr, typ)
}
Expand Down

0 comments on commit b219038

Please sign in to comment.