Skip to content

cgen incorrect order in for loop #25398

Description

@Xyndra

Describe the bug

VV_LOC int main__find_word_end(Array_rune text, int start) {
	int i = start;
	for (;;) {
		bool _t1 = (i < text.len);
		bool _t2 = (Array_rune_contains(_const_main__consonants, (*(rune*)builtin__array_get(text, i))));
		if (!( _t1 && ( _t2 || Array_rune_contains(_const_main__vowels, (*(rune*)builtin__array_get(text, i)))))) break;
		i++;
	}
	return i;
}

Reproduction Steps

fn find_word_end(text []rune, start int) int {
	mut i := start
	for i < text.len && (consonants.contains(text[i]) || vowels.contains(text[i])) {
		i++
	}
	return i
}

Expected Behavior

works in the correct order (left to right)

Current Behavior

part get taken out, leading to V panic: array.get: index out of range (i,a.len):61, 61

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.12 6762c9a

Environment details (OS name and version, etc.)

V full version V 0.4.12 c221b32.6762c9a
OS windows, Microsoft Windows 11 Pro 22635 64-bit
Processor 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory 34.62GB/63.67GB
V executable D:\software\v\v.exe
V last modified time 2025-09-26 19:51:30
V home dir OK, value: D:\software\v
VMODULES OK, value: C:\Users\Sammy.vmodules
VTMP OK, value: C:\Users\Sammy\AppData\Local\Temp\v_0
Current working dir OK, value: D:\Code\v\bwinf_44_1_2
Git version git version 2.51.0.windows.1
V git status weekly.2025.16-830-g6762c9a6
.git/config present true
cc version cc (Rev2, Built by MSYS2 project) 13.2.0
gcc version gcc (Rev2, Built by MSYS2 project) 13.2.0
clang version clang version 21.1.2
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status thirdparty-windows-amd64 b425ac82
emcc version emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.3 (a9651ff57165f5710bb09a5fe52590fd6ddb72df)
glibc version N/A

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 fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions