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:
parent
b6ecd634e3
commit
d0a873ca02
@ -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])
|
||||
}
|
||||
|
11
vlib/v/tests/print_address_of_reference_struct_test.v
Normal file
11
vlib/v/tests/print_address_of_reference_struct_test.v
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user