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

checker: fix printing address of integer variable (#17327)

This commit is contained in:
yuyi 2023-02-16 02:05:26 +08:00 committed by GitHub
parent 2382549df3
commit 289993ad7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -83,14 +83,15 @@ fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type {
if node.pluss[i] && !typ.is_number() {
c.error('plus prefix only allowed for numbers', node.fmt_poss[i])
}
if (typ.is_unsigned() && fmt !in [`u`, `x`, `X`, `o`, `c`, `b`])
if ((typ.is_unsigned() && fmt !in [`u`, `x`, `X`, `o`, `c`, `b`])
|| (typ.is_signed() && fmt !in [`d`, `x`, `X`, `o`, `c`, `b`])
|| (typ.is_int_literal()
&& fmt !in [`d`, `c`, `x`, `X`, `o`, `u`, `x`, `X`, `o`, `b`])
|| (typ.is_float() && fmt !in [`E`, `F`, `G`, `e`, `f`, `g`])
|| (typ.is_pointer() && fmt !in [`p`, `x`, `X`])
|| (typ.is_string() && fmt !in [`s`, `S`])
|| (typ.idx() in [ast.i64_type_idx, ast.f64_type_idx] && fmt == `c`) {
|| (typ.idx() in [ast.i64_type_idx, ast.f64_type_idx] && fmt == `c`))
&& !(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,14 @@
fn test_print_address_of_reference_base_type() {
a1 := 22
println('${&a1:p}')
a2 := 22.22
println('${&a2:p}')
a3 := `a`
println('${&a3:p}')
a4 := 'hello'
println('${&a4:p}')
a5 := true
println('${&a5:p}')
assert true
}