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

checker: fix printing the address of a struct value with println('${&value:p}') (#17321)

This commit is contained in:
yuyi 2023-02-15 17:20:25 +08:00 committed by GitHub
parent b6ecd634e3
commit d0a873ca02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -95,7 +95,8 @@ fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type {
node.fmt_poss[i])
}
if c.table.final_sym(typ).kind in [.array, .array_fixed, .struct_, .interface_, .none_, .map, .sum_type]
&& fmt in [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `p`, `b`] {
&& fmt in [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `p`, `b`]
&& !(typ.is_ptr() && fmt in [`p`, `x`, `X`]) {
c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`',
node.fmt_poss[i])
}

View File

@ -0,0 +1,11 @@
struct Foo {
abc int
}
fn test_print_address_of_reference_struct() {
foo := Foo{}
foo_ptr := &foo
println('${foo_ptr:p}')
println('${&foo:p}')
assert true
}