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

compiler panic for |i, e| '${i}: ${e}' lambda expr used as callback in a generic function #22497

Open
spytheman opened this issue Oct 12, 2024 · 1 comment · May be fixed by #22509
Open

compiler panic for |i, e| '${i}: ${e}' lambda expr used as callback in a generic function #22497

spytheman opened this issue Oct 12, 2024 · 1 comment · May be fixed by #22509
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Compiler Panic The V compiler itself paniced. It should not, it should produce nice and readable errors instead. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@spytheman
Copy link
Member

spytheman commented Oct 12, 2024

V doctor:

V full version: V 0.4.8 51b471b.0cf3a44
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-12 05:47:32

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: weekly.2024.41-15-g0cf3a445
.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 bug.v

fn mapi[T, U](arr []T, callback fn (int, T) U) []U {
    mut mapped := []U{}
    for i, el in arr {
        mapped << callback(i, el)
    }
    return mapped
}

fn main() {
    arr := [`a`, `b`, `c`, `d`]
    mapped_arr := mapi(arr, |i, e| '${i}: ${e}') //panics
    dump(mapped_arr)
}

// mapi[rune,string](arr, |i, e| '${i}: ${e}')  // works
// mapi(arr, fn (i int, e rune) string { return '${i}: ${e}' }) // works

What did you expect to see?

a compiled program

What did you see instead?

================ V panic ================
   module: builtin
 function: get()
  message: array.get: index out of range (i == 1, a.len == 1)
     file: /space/v/oo/vlib/builtin/array.v:454
   v hash: 0cf3a44
=========================================
/tmp/v_1000/../../../../../../space/v/oo/vlib/builtin/builtin.c.v:87: at panic_debug: Backtrace
/tmp/v_1000/../../../../../../space/v/oo/vlib/builtin/array.v:454: by array_get
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/check_types.v:1099: by v__checker__Checker_infer_fn_generic_types
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/fn.v:1602: by v__checker__Checker_fn_call
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/fn.v:652: by v__checker__Checker_call_expr
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/checker.v:2854: by v__checker__Checker_expr
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/assign.v:34: by v__checker__Checker_assign_stmt
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/checker.v:2108: by v__checker__Checker_stmt
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/checker.v:2715: by v__checker__Checker_stmts_ending_with_expression
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/checker.v:2683: by v__checker__Checker_stmts
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/fn.v:496: by v__checker__Checker_fn_decl
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/checker.v:2195: by v__checker__Checker_stmt
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/checker.v:267: by v__checker__Checker_check
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/checker/checker.v:329: by v__checker__Checker_check_files
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/builder/builder.v:131: by v__builder__Builder_middle_stages
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/builder/builder.v:158: by v__builder__Builder_front_and_middle_stages
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/builder/cbuilder/cbuilder.v:71: by v__builder__cbuilder__gen_c
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/builder/cbuilder/cbuilder.v:59: by v__builder__cbuilder__build_c
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/builder/cbuilder/cbuilder.v:49: by v__builder__cbuilder__compile_c
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/builder/rebuilding.v:324: by v__builder__Builder_rebuild
/tmp/v_1000/../../../../../../space/v/oo/vlib/v/builder/compile.v:17: by v__builder__compile
/tmp/v_1000/../../../../../../space/v/oo/cmd/v/v.v:187: by main__rebuild
/tmp/v_1000/../../../../../../space/v/oo/cmd/v/v.v:145: by main__main
/tmp/v_1000/../../../../../../tmp/v_1000/vdbg.01J9ZM9EF63XZSKVN55J4MHB16.tmp.c:59228: by main

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. Compiler Panic The V compiler itself paniced. It should not, it should produce nice and readable errors instead. labels Oct 12, 2024
@spytheman
Copy link
Member Author

This bug was discovered by @heyimtcn and reported in the V Discord https://discord.com/channels/592103645835821068/700746775962714232/1294224298965340191 .
I am only filing it here.

@felipensp felipensp self-assigned this Oct 13, 2024
@felipensp felipensp added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Oct 13, 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. Compiler Panic The V compiler itself paniced. It should not, it should produce nice and readable errors instead. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants