Skip to content

Commit 289993a

Browse files
authored
checker: fix printing address of integer variable (#17327)
1 parent 2382549 commit 289993a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

vlib/v/checker/str.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type {
8383
if node.pluss[i] && !typ.is_number() {
8484
c.error('plus prefix only allowed for numbers', node.fmt_poss[i])
8585
}
86-
if (typ.is_unsigned() && fmt !in [`u`, `x`, `X`, `o`, `c`, `b`])
86+
if ((typ.is_unsigned() && fmt !in [`u`, `x`, `X`, `o`, `c`, `b`])
8787
|| (typ.is_signed() && fmt !in [`d`, `x`, `X`, `o`, `c`, `b`])
8888
|| (typ.is_int_literal()
8989
&& fmt !in [`d`, `c`, `x`, `X`, `o`, `u`, `x`, `X`, `o`, `b`])
9090
|| (typ.is_float() && fmt !in [`E`, `F`, `G`, `e`, `f`, `g`])
9191
|| (typ.is_pointer() && fmt !in [`p`, `x`, `X`])
9292
|| (typ.is_string() && fmt !in [`s`, `S`])
93-
|| (typ.idx() in [ast.i64_type_idx, ast.f64_type_idx] && fmt == `c`) {
93+
|| (typ.idx() in [ast.i64_type_idx, ast.f64_type_idx] && fmt == `c`))
94+
&& !(typ.is_ptr() && fmt in [`p`, `x`, `X`]) {
9495
c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`',
9596
node.fmt_poss[i])
9697
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn test_print_address_of_reference_base_type() {
2+
a1 := 22
3+
println('${&a1:p}')
4+
a2 := 22.22
5+
println('${&a2:p}')
6+
a3 := `a`
7+
println('${&a3:p}')
8+
a4 := 'hello'
9+
println('${&a4:p}')
10+
a5 := true
11+
println('${&a5:p}')
12+
13+
assert true
14+
}

0 commit comments

Comments
 (0)