vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.66k stars 2.15k forks source link

Internal panic when use `init1` in `[]int{}` fields with `-check` flag #18559

Open i582 opened 1 year ago

i582 commented 1 year ago

Describe the bug

Code: https://vosca.dev/p/15eef0cf92

arr := []int{len: 100, cap: 200, init1: index * 3}
println(arr)

Expected Behavior

Checker error

Current Behavior

Output:

V panic: sym: invalid type (typ=ast.Type(0x0 = 0) idx=0). Compiler bug. This should never happen. Please report the bug using `v bug file.v`.

v hash: ec35d76
/tmp/v_0/v2.10797243524902215257.tmp.c:21184: at _v_panic: Backtrace
/tmp/v_0/v2.10797243524902215257.tmp.c:47193: by v__ast__default_table_panic_handler
/tmp/v_0/v2.10797243524902215257.tmp.c:47200: by v__ast__Table_panic
/tmp/v_0/v2.10797243524902215257.tmp.c:47917: by v__ast__Table_sym
/tmp/v_0/v2.10797243524902215257.tmp.c:21: by v__checker__Checker_infix_expr
/tmp/v_0/v2.10797243524902215257.tmp.c:57026: by v__checker__Checker_expr
/tmp/v_0/v2.10797243524902215257.tmp.c:52416: by v__checker__Checker_assign_stmt
/tmp/v_0/v2.10797243524902215257.tmp.c:56022: by v__checker__Checker_stmt
/tmp/v_0/v2.10797243524902215257.tmp.c:56588: by v__checker__Checker_stmts_ending_with_expression
/tmp/v_0/v2.10797243524902215257.tmp.c:56564: by v__checker__Checker_stmts
/tmp/v_0/v2.10797243524902215257.tmp.c:62419: by v__checker__Checker_fn_decl
/tmp/v_0/v2.10797243524902215257.tmp.c:56102: by v__checker__Checker_stmt
/tmp/v_0/v2.10797243524902215257.tmp.c:54250: by v__checker__Checker_check
/tmp/v_0/v2.10797243524902215257.tmp.c:54317: by v__checker__Checker_check_files
/tmp/v_0/v2.10797243524902215257.tmp.c:43205: by v__builder__Builder_middle_stages
/tmp/v_0/v2.10797243524902215257.tmp.c:43236: by v__builder__Builder_front_and_middle_stages
/tmp/v_0/v2.10797243524902215257.tmp.c:45553: by v__builder__cbuilder__gen_c
/tmp/v_0/v2.10797243524902215257.tmp.c:45536: by v__builder__cbuilder__build_c
/tmp/v_0/v2.10797243524902215257.tmp.c:45526: by v__builder__cbuilder__compile_c
/tmp/v_0/v2.10797243524902215257.tmp.c:45437: by v__builder__Builder_rebuild
/tmp/v_0/v2.10797243524902215257.tmp.c:44626: by v__builder__compile
/tmp/v_0/v2.10797243524902215257.tmp.c:45874: by main__rebuild
/tmp/v_0/v2.10797243524902215257.tmp.c:45824: by main__main
/tmp/v_0/v2.10797243524902215257.tmp.c:46877: by main
Exited with error status 1

Reproduction Steps

Run code above with -check flag

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.3.4 fc4c431.45f16a2

Environment details (OS name and version, etc.)

V full version: V 0.3.4 fc4c431.ec35d76
OS: linux, Ubuntu 22.04.2 LTS
Processor: 2 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz

getwd: /home/pmakhnev/playground
vexe: /home/pmakhnev/v/v
vexe mtime: 2023-06-25 12:00:07

vroot: OK, value: /home/pmakhnev/v
VMODULES: OK, value: /root/.vmodules
VTMP: OK, value: /tmp/v_0

Git version: git version 2.34.1
Git vroot status: weekly.2023.25-35-gec35d765
.git/config present: true

CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
yuyi98 commented 1 year ago

It throws an error during the parser phase, so -check is unpredictble.