Skip to content

Commit

Permalink
checker: fix json.encode_pretty with a struct init expression argum…
Browse files Browse the repository at this point in the history
…ent (#22897)
  • Loading branch information
ttytm authored Nov 18, 2024
1 parent 47c7858 commit 3bf459c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions vlib/json/tests/json_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,13 @@ fn test_omit_empty() {
// println(json.encode_pretty(foo))
}

fn test_encode_struct_expression() {
assert json.encode(Foo2{'Foo'}) == '{"name":"Foo"}'
assert json.encode_pretty(Foo2{'Bar'}) == '{
"name": "Bar"
}'
}

struct Asdasd {
data GamePacketData
}
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,8 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
|| final_param_sym.idx == ast.voidptr_type_idx
|| param.typ == ast.nil_type || final_param_sym.idx == ast.nil_type_idx)
&& !call_arg.typ.is_any_kind_of_pointer() && func.language == .v
&& !call_arg.expr.is_lvalue() && func.name != 'json.encode' && !c.pref.translated
&& !c.file.is_translated {
&& !call_arg.expr.is_lvalue() && !c.pref.translated && !c.file.is_translated
&& func.name !in ['json.encode', 'json.encode_pretty'] {
c.error('expression cannot be passed as `voidptr`', call_arg.expr.pos())
}
// Handle expected interface
Expand Down

0 comments on commit 3bf459c

Please sign in to comment.