cgen: fix showing the expression, as literal value, in case of assert s[x..y] == "literal" (fix #24103) (#24105)

This commit is contained in:
Delyan Angelov 2025-04-01 17:37:52 +03:00 committed by GitHub
parent a59b717daa
commit 42ac6885df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 5 deletions

View File

@ -207,12 +207,8 @@ fn (mut g Gen) gen_assert_single_expr(expr ast.Expr, typ ast.Type) {
g.write(ctoslit(expr_str)) g.write(ctoslit(expr_str))
} }
ast.IndexExpr { ast.IndexExpr {
if expr.index is ast.RangeExpr {
g.write(ctoslit(expr_str))
} else {
g.gen_expr_to_string(expr, typ) g.gen_expr_to_string(expr, typ)
} }
}
ast.PrefixExpr { ast.PrefixExpr {
if expr.right is ast.CastExpr { if expr.right is ast.CastExpr {
// TODO: remove this check; // TODO: remove this check;

View File

@ -3,3 +3,8 @@ vlib/v/tests/skip_unused/assert_works_test.vv:2: fn test_abc
Left value (len: 3): `abc` Left value (len: 3): `abc`
Right value (len: 3): `xyz` Right value (len: 3): `xyz`
vlib/v/tests/skip_unused/assert_works_test.vv:7: fn test_index_expr
> assert example_string[1 .. 4] == 'abcdef'
Left value (len: 3): `his`
Right value (len: 6): `abcdef`

View File

@ -3,3 +3,8 @@ vlib/v/tests/skip_unused/assert_works_test.vv:2: fn test_abc
Left value (len: 3): `abc` Left value (len: 3): `abc`
Right value (len: 3): `xyz` Right value (len: 3): `xyz`
vlib/v/tests/skip_unused/assert_works_test.vv:7: fn test_index_expr
> assert example_string[1 .. 4] == 'abcdef'
Left value (len: 3): `his`
Right value (len: 6): `abcdef`

View File

@ -1,3 +1,8 @@
fn test_abc() { fn test_abc() {
assert 'abc' == 'xyz' assert 'abc' == 'xyz'
} }
fn test_index_expr() {
example_string := 'This is an example string'
assert example_string[1..4] == 'abcdef'
}