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

checker error when a lambda expression is used as a parameter to a generic function that accepts a fn callback #22384

Closed
spytheman opened this issue Oct 1, 2024 · 0 comments · Fixed by #22387
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@spytheman
Copy link
Member

spytheman commented Oct 1, 2024

V doctor:

V full version: V 0.4.8 4ee948f.e598db1
OS: linux, Ubuntu 20.04.6 LTS
Processor: 2 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /space/v/oo
vexe: /space/v/oo/v
vexe mtime: 2024-10-01 13:24:57

vroot: OK, value: /space/v/oo
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.0
Git vroot status: 0.4.8-14-ge598db12-dirty (4 commit(s) behind V master)
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

What did you do?
./v -g -o vdbg cmd/v && ./vdbg generic_fn_called_with_lambda.v

import arrays

items := ['item1', 'item2', 'item3']
list := arrays.map_indexed[string, string](items, |i, item| '${i}. ${item}')
println(list)

What did you expect to see?

a compiled program, producing ['0. item1', '1. item2', '2. item3']

What did you see instead?

generic_fn_called_with_lambda.v:4:70: error: no known default format for type `T`
    2 | 
    3 | items := ['item1', 'item2', 'item3']
    4 | list := arrays.map_indexed[string, string](items, |i, item| '${i}. ${item}')
      |                                                                      ~~~~
    5 | println(list)
generic_fn_called_with_lambda.v:4:60: error: cannot use `string` as type `R` in return argument
    2 | 
    3 | items := ['item1', 'item2', 'item3']
    4 | list := arrays.map_indexed[string, string](items, |i, item| '${i}. ${item}')
      |                                                            ~~~~~~~~~~~~~~~~
    5 | println(list)

Note: the full version works:

import arrays
items := ['item1', 'item2', 'item3']
list := arrays.map_indexed[string, string](items, fn(i int, item string) string { return '${i}. ${item}' })
println(list)

Probably related: #22109 .

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. labels Oct 1, 2024
@felipensp felipensp self-assigned this Oct 2, 2024
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. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants