Repository navigation
Checker error when only destructuring first of multiple return types, then passing it to a functionย #23735
Copy link
Copy link
Closed
Labels
BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.This bug has been confirmed to be valid by a contributor.Unit: CheckerBugs/feature requests, that are related to the type checker.Bugs/feature requests, that are related to the type checker.
Description
Describe the bug
A checker error happens when you only destructure the first of multiple return types, then pass it to a function
Reproduction Steps
fn some_fn() (int, int) {}
fn some_fn2() {
ret := some_fn()
some_fn3(ret)
}
fn some_fn3(param int) {}Expected Behavior
No checker error
Current Behavior
V panic: array.get: index out of range (i,a.len):1, 1
v hash: ae899e6
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:19317: at _v_panic: Backtrace
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:19348: by panic_n2
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:18893: by array_get
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:61395: by v__checker__Checker_fn_call
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:60370: by v__checker__Checker_call_expr
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:52807: by v__checker__Checker_expr
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:51986: by v__checker__Checker_stmt
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:52570: by v__checker__Checker_stmts_ending_with_expression
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:52547: by v__checker__Checker_stmts
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:60166: by v__checker__Checker_fn_decl
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:52020: by v__checker__Checker_stmt
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:49896: by v__checker__Checker_check
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:49959: by v__checker__Checker_check_files
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:48762: by v__builder__Builder_middle_stages
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:48800: by v__builder__Builder_front_and_middle_stages
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:51814: by v__builder__cbuilder__gen_c
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:51786: by v__builder__cbuilder__build_c
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:51777: by v__builder__cbuilder__compile_c
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:51685: by v__builder__Builder_rebuild
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:50376: by v__builder__compile
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:52205: by main__rebuild
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:52121: by main__main
C:/Users/user/AppData/Local/Temp/v_0/v2.01JM5P29B6R1YX1EQEY4JKX76B.tmp.c:52860: by wmain
00bcbc40 : by ???
00bcbda3 : by ???
Possible Solution
No response
Additional Information/Context
By directly passing the function's return type and not destructuring only the first return, the checker error disappears
fn some_fn() (int, int) {}
fn some_fn2() {
// The below will not get a checker error
some_fn3(some_fn())
}
fn some_fn3(param int) {}V version
V 0.4.9 17f3c8f.ae899e6
Environment details (OS name and version, etc.)
| V full version | V 0.4.9 17f3c8f.ae899e6 |
|---|---|
| OS | windows, Microsoft Windows 11 Pro 26100 64-bit |
| Processor | 12 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i5-12600 |
| Memory | 40.28GB/63.76GB |
| V executable | C:\dev_tools\v\v.exe |
| V last modified time | 2025-02-15 20:51:16 |
| V home dir | OK, value: C:\dev_tools\v |
| VMODULES | OK, value: C:\Users\user.vmodules |
| VTMP | OK, value: C:\Users\user\AppData\Local\Temp\v_0 |
| Current working dir | OK, value: C:\dev\v\winmd |
| Git version | git version 2.45.1.windows.1 |
| V git status | weekly.2025.03-141-gae899e67 (3 commit(s) behind V master) |
| .git/config present | true |
| cc version | N/A |
| gcc version | N/A |
| clang version | N/A |
| msvc version | N/A |
| tcc version | tcc version 0.9.27 (x86_64 Windows) |
| tcc git status | thirdparty-windows-amd64 b425ac82 |
| emcc version | N/A |
| glibc version | ldd (cygwin) 2.5.0 |
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.This bug has been confirmed to be valid by a contributor.Unit: CheckerBugs/feature requests, that are related to the type checker.Bugs/feature requests, that are related to the type checker.
Activity
huly-for-github commentedon Feb 15, 2025
Connected to Hulyยฎ: V_0.6-22153
larpon commentedon Feb 16, 2025
Good catch