Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v compiler doesn't recognize interface type when passing to array method #22298

Closed
daansystems opened this issue Sep 24, 2024 · 2 comments · Fixed by #22307
Closed

v compiler doesn't recognize interface type when passing to array method #22298

daansystems opened this issue Sep 24, 2024 · 2 comments · Fixed by #22307

Comments

@daansystems
Copy link

daansystems commented Sep 24, 2024

V doctor:

V full version: V 0.4.7 18eee34.4ee948f
OS: windows, Microsoft Windows 11 Pro v22631 64-bit
Processor: 24 cpus, 64bit, little endian, 

getwd: D:\vbug
vexe: C:\v\v.exe
vexe mtime: 2024-09-24 17:12:18

vroot: OK, value: C:\v
VMODULES: OK, value: C:\Users\info\.vmodules
VTMP: OK, value: C:\Users\info\AppData\Local\Temp\v_0

Git version: git version 2.42.0.windows.2
Git vroot status: weekly.2024.39-5-g4ee948fe-dirty
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,

operable program or batch file.


thirdparty/tcc status: thirdparty-windows-amd64 b425ac82

What did you do?
./v -g -o vdbg cmd/v && ./vdbg src\main.v

module main

interface IGameObject {
	mut:
	name string
}

struct GameObject implements IGameObject {
mut:
	name string
}

struct Game {
mut:
	objects        []IGameObject
}

fn (mut game Game) gc() {
	for obj in game.objects {
		game.objects.delete(obj)
	}
	game.objects.clear()
}

fn main() {}

What did you expect to see?

no c compiler error

What did you see instead?

================== C compilation error (from tcc): ==============
cc: C:/Users/info/AppData/Local/Temp/v_0/main.01J8JMB0XJMWQ088W3RH9WNT80.tmp.c:7068: warning: implicit declaration of function 'tcc_backtrace'
cc: C:/Users/info/AppData/Local/Temp/v_0/main.01J8JMB0XJMWQ088W3RH9WNT80.tmp.c:13536: error: cannot convert 'struct main__IGameObject' to 'int'
... (the original output was 3 lines long, and was truncated to 2 lines)
=================================================================
(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 .

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.

@yuyi98
Copy link
Member

yuyi98 commented Sep 25, 2024

game.objects.delete(obj) ?
The array delete() has no such usage, Of course we should check for errors.

@StunxFS
Copy link
Contributor

StunxFS commented Sep 25, 2024

@daansystems To delete the elements of the array, you could use the following:

fn (mut game Game) gc() {
	for i, mut obj in game.objects {
		unsafe { obj.free() }
		game.objects.delete(i)
	}
	game.objects.clear()
}

Note that if you want to free the gc Game object, the method must be called free and not gc (gc has no special meaning to the compiler, free does).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants