V: infix expr: cannot use `map_string_string` (right expression) as `x.json2.decode`

Created on 3 Nov 2020  路  8Comments  路  Source: vlang/v

V version: V 0.1.29 aecdfb0
OS: Windows 10 WSL2 Ubuntu 20.04

What did you do?

import x.json2

fn main() {
    test := '{}'
    a := json2.decode<map[string]string>(test)
}

What did you expect to see?
works

What did you see instead?

test.v:5:19: error: infix expr: cannot use `map_string_string` (right expression) as `x.json2.decode`
    3 | fn main() {
    4 |     test := '{}'
    5 |     a := json2.decode<map[string]string>(test)
      |                      ^
    6 | }
Bug

Most helpful comment

List what features we need in comptime, then we implement that first. Otherwise we have to refactor everytime.

All 8 comments

the error now:

main.v:5:2: warning: unused variable: `a`
    3 | fn main() {
    4 |     test := '{}'
    5 |     a := json2.decode<map[string]string>(test)
      |     ^
    6 | }
/code/root/v/vlib/x/json2/json2.v:30:6: error: unknown method: `map[string]string.from_json`
   28 |     }
   29 |     mut typ := T{}
   30 |     typ.from_json(res)
      |         ~~~~~~~~~~~~~~
   31 |     return typ
   32 | }

@nedpals can we make this work without from_json?

@nedpals can we make this work without from_json?

I'm working on a codegen right now. I'll be posting the draft PR later.

Can you do it without compiler magic? Doing it with $for $if would be awesome!

Thats my first idea but then there are lots of limitations when using $if and $for. No worries though, the codegen will be the same as the enum flag where it adds additional V code at the end.

I'll be switching to comptime for and if similar to the docs once they're OK to use now

List what features we need in comptime, then we implement that first. Otherwise we have to refactor everytime.

True. I'll be writing a separate issue for this to address the issues.

Was this page helpful?
0 / 5 - 0 ratings