Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic type for map value cannot be inferred from a value argument #18337

Closed
prantlf opened this issue Jun 3, 2023 · 0 comments · Fixed by #18341
Closed

Generic type for map value cannot be inferred from a value argument #18337

prantlf opened this issue Jun 3, 2023 · 0 comments · Fixed by #18341
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@prantlf
Copy link

prantlf commented Jun 3, 2023

Describe the bug

Compiling this code:

fn f[T](src map[string]T) {
}

f({ 'a': 1 })

fails with the following error:

bug_map.v:6:10: error: invalid map value: expected `T`, not `int literal`
    4 | // m := { 'a': 1 }
    5 | // f(m)
    6 | f({ 'a': 1 })
      |          ^

Expected Behavior

The compilation should succeed resolving the function to:

fn f[int](src map[string]int)

Current Behavior

The compilation fails with the message above.

Reproduction Steps

  1. Save the script above to a file bug_map.v.
  2. Run v bug_map.v on the command line.

Or try it at https://vosca.dev/p/27605a3527.

Possible Solution

I wish I knew :-)

Additional Information/Context

It appears to be connected to maybe just parsing the value and not storing temporarily its type. If the value argument in the function call:

f({ 'a': 1 })

is replaced with a variable, which has probably its type generated, the compilation succeeds:

m := { 'a': 1 }
f(m)

See at https://vosca.dev/p/2d10eaa9f8.

V version

V 0.3.4 4e21b2a

Environment details (OS name and version, etc.)

V full version: V 0.3.4 1be798b.4e21b2a
OS: macos, macOS, 13.3.1, 22E772610a
Processor: 12 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz

getwd: /Users/prantlf/Sources/github/v-yaml
vexe: /usr/local/Cellar/vlang/0.3.4/libexec/v
vexe mtime: 2023-06-03 11:39:19

vroot: OK, value: /usr/local/Cellar/vlang/0.3.4/libexec
VMODULES: OK, value: /Users/prantlf/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.41.0
Git vroot status: weekly.2023.22-6-g4e21b2ab
.git/config present: true

CC version: Apple clang version 14.0.3 (clang-1403.0.22.14.1)
thirdparty/tcc status: thirdparty-macos-amd64 46662e2

@prantlf prantlf added the Bug This tag is applied to issues which reports bugs. label Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant