v icon indicating copy to clipboard operation
v copied to clipboard

Bug when compiling pure v code

Open vsm0 opened this issue 9 months ago • 5 comments

V version: V 0.4.10 9b1937a, press to see full `v doctor` output
V full version V 0.4.10 e1b9054a27b578a46b1011910b2d632511db8e75.9b1937a
OS linux, Linux version 6.14.4-arch1-2 (linux@archlinux) (gcc (GCC) 15.1.1 20250425, GNU ld (GNU Binutils) 2.44.0) #1 SMP PREEMPT_DYNAMIC Tue, 29 Apr 2025 09:23:13 +0000
Processor 2 cpus, 64bit, little endian, Intel(R) Celeron(R) CPU N2840 @ 2.16GHz
Memory 0.19GB/1.8GB
V executable /usr/lib/vlang/v
V last modified time 2025-05-09 09:30:07
V home dir NOT writable, value: /usr/lib/vlang
VMODULES OK, value: /home/usr/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/usr/prog/vlang/quickie
Git version git version 2.49.0
V git status Error: fatal: not a git repository (or any of the parent directories): .git
.git/config present false
cc version cc (GCC) 15.1.1 20250425
gcc version gcc (GCC) 15.1.1 20250425
clang version clang version 19.1.7
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status N/A
emcc version N/A
glibc version ldd (GNU libc) 2.41

What did you do? ./v -g -o vdbg cmd/v && ./vdbg main.v && main See attached file main.v

What did you see?

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/main.01JV265YF36SKRS1M1NE19EJRR.tmp.c:3345: error: 'main__Entity_name_table' undeclared
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

What did you expect to see?

a window opens, and a player is controllable in a space with enemies closing in, the fps printing in the bottom left

[!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.

vsm0 avatar May 12 '25 12:05 vsm0

Connected to Huly®: V_0.6-22835

huly-for-github[bot] avatar May 12 '25 12:05 huly-for-github[bot]

this occured right after I added the self.entities.sort(...) line, of an array of interface Entity

vsm0 avatar May 12 '25 12:05 vsm0

I was able to reproduce the error with a small sample (as opposed to giving my huge source file):

module main

interface Person {
	identify() int
}

struct Boy {}
fn (self Boy) identify() int { return 0 }

struct Girl {}
fn (self Girl) identify() int { return 1 }

fn main() {
	mut ppl := []Person{}
	ppl << &Boy{}
	ppl << &Girl{}

	ppl.sort(a.identify() < b.identify())
}

vsm0 avatar May 12 '25 12:05 vsm0

This is a workaround thanks V's interfaces also define fields:

interface Person { identify int }

struct Boy { identify int }

struct Girl { identify int = 1 }

fn main() {
	mut ppl := []Person{}
	ppl << &Boy{}
	ppl << &Girl{}
	ppl.sort(a.identify < b.identify)
}

jorgeluismireles avatar May 12 '25 15:05 jorgeluismireles

Yeah, you can also use sort_with_compare and a custom comparator

vsm0 avatar May 12 '25 21:05 vsm0