Skip to content

checker: panic with __global + fixed-size array + range loop in method #26324

Description

@fleximus

Describe the bug

Checker crash triggered by the presence of __global in a file that also defines a struct with a fixed-size array and a method that loops for i in 0 .. buf_len to write into that array

Reproduction Steps

bug.v:

module main

const buf_len = 256

__global not_used_in_code_but_helps_triggering = u64(-1)

struct Buffer {
mut:
	data [256]u8
	pos  int
}

fn (mut buf Buffer) clear() {
	buf.pos = 0
	for i in 0 .. buf_len {
		buf.data[i] = 0
	}
}

Check with v -check bug.v

Expected Behavior

Properly report run without the crash - a normal diagnostic about globals requiring -enable-globals, or otherwise complete checking without a panic.

Current Behavior

V panic: table.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: 2ce4090
    pid: 0x1b69c4
    tid: 0x1b69c4
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:22301: at builtin___v_panic: Backtrace
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:38675: by v__ast__default_table_panic_handler
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:38681: by v__ast__Table_panic
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:39398: by v__ast__Table_sym
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:11450: by v__checker__Checker_struct_init
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:59787: by v__checker__Checker_expr
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:1267: by v__checker__Checker_map_init
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:59390: by v__checker__Checker_expr
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:1267: by v__checker__Checker_map_init
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:59390: by v__checker__Checker_expr
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:58078: by v__checker__Checker_stmt
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:58761: by v__checker__Checker_stmts_ending_with_expression
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:58738: by v__checker__Checker_stmts
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:2224: by v__checker__Checker_fn_decl
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:58143: by v__checker__Checker_stmt
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:55832: by v__checker__Checker_check
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:55938: by v__checker__Checker_check_files
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:60083: by v__builder__Builder_middle_stages
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:60132: by v__builder__Builder_front_and_middle_stages
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:62691: by v__builder__cbuilder__gen_c
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:62663: by v__builder__cbuilder__build_c
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:62654: by v__builder__cbuilder__compile_c
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:62571: by v__builder__Builder_rebuild
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:61717: by v__builder__compile
/tmp/v_1000/v2.01KEPF1JHXSAKTA678XYJMXHBB.tmp.c:63083: by main__rebuild

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.5.0 2ce4090

Environment details (OS name and version, etc.)

V full version: V 0.5.0 9a73766.2ce4090
OS: Linux

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.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions