1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix an error with ptr interpolation (fix #19048) (#19049)

This commit is contained in:
shove 2023-08-03 16:18:22 +08:00 committed by GitHub
parent ef5c3cdb73
commit 9f5e9ba1cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -167,13 +167,13 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int, fmts []u8) {
if typ == ast.string_type && g.comptime_for_method.len == 0 { if typ == ast.string_type && g.comptime_for_method.len == 0 {
if g.inside_vweb_tmpl { if g.inside_vweb_tmpl {
g.write('vweb__filter(') g.write('vweb__filter(')
if expr.is_auto_deref_var() { if expr.is_auto_deref_var() && fmt != `p` {
g.write('*') g.write('*')
} }
g.expr(expr) g.expr(expr)
g.write(')') g.write(')')
} else { } else {
if expr.is_auto_deref_var() { if expr.is_auto_deref_var() && fmt != `p` {
g.write('*') g.write('*')
} }
g.expr(expr) g.expr(expr)
@ -221,13 +221,13 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int, fmts []u8) {
g.expr(expr) g.expr(expr)
g.write(')') g.write(')')
} else { } else {
if expr.is_auto_deref_var() { if expr.is_auto_deref_var() && fmt != `p` {
g.write('*') g.write('*')
} }
g.expr(expr) g.expr(expr)
} }
} else { } else {
if expr.is_auto_deref_var() { if expr.is_auto_deref_var() && fmt != `p` {
g.write('*') g.write('*')
} }
g.expr(expr) g.expr(expr)

View File

@ -201,3 +201,19 @@ fn test_call() {
s := '${f(4)}' s := '${f(4)}'
assert s == '4' assert s == '4'
} }
// for issue: 19048
struct Foo {
}
fn (mut f Foo) intp_pointer() string {
return '${f:p}'
}
fn test_intp_pointer_specifier_p() {
mut foo := Foo{}
str1 := foo.intp_pointer()
str2 := '${&foo:p}'
assert str1 == str2
}