Skip to content

Assigning to optional give c error: expected struct or union but not 'struct main__IGameObject *' #24292

Description

@daansystems
V version: V 0.4.10 b76b1ee, press to see full `v doctor` output
V full version V 0.4.10 5c65e58.b76b1ee
OS windows, Microsoft Windows 11 Pro 26100 64-bit
Processor 24 cpus, 64bit, little endian, AMD Ryzen 9 3900X 12-Core Processor
Memory 11.33GB/31.9GB
V executable C:\v\v.exe
V last modified time 2025-04-22 07:58:32
V home dir OK, value: C:\v
VMODULES OK, value: C:\Users\info.vmodules
VTMP OK, value: C:\Users\info\AppData\Local\Temp\v_0
Current working dir OK, value: D:\vbug2
Git version git version 2.42.0.windows.2
V git status weekly.2025.14-82-gb76b1ee7-dirty
.git/config present true
cc version N/A
gcc version N/A
clang version clang version 17.0.1
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status thirdparty-windows-amd64 b425ac82
emcc version N/A
glibc version ldd (cygwin) 3.4.7

What did you do?
./v -g -o vdbg cmd/v && ./vdbg main.v && D:\vbug2\main.exe

module main

@[heap]
interface IGameObject {
mut:
	name       string
	parent     ?&IGameObject
	next       ?&IGameObject
	child      ?&IGameObject
	last_child ?&IGameObject
	add_child(mut o IGameObject)
}

@[heap]
struct GameObject implements IGameObject {
mut:
	name       string
	parent     ?&IGameObject
	next       ?&IGameObject
	child      ?&IGameObject
	last_child ?&IGameObject
}

fn (mut gameobject GameObject) add_child(mut o IGameObject) {
	o.parent = gameobject
	if gameobject.last_child != none {
		gameobject.last_child.next = o
	} else {
		gameobject.child = o
	}
	gameobject.last_child = o
}

fn main() {
	mut v1 := &GameObject{
		name: 'v1'
	}
	mut v2 := &GameObject{
		name: 'v2'
	}
	v1.add_child(mut v2)
}

What did you see?

================== C compilation error (from tcc): ==============
cc: C:/Users/info/AppData/Local/Temp/v_0/main.01JSE8KMQVRCSRQAW4QH7519FF.tmp.c:3852: warning: implicit declaration of function 'tcc_backtrace'
cc: C:/Users/info/AppData/Local/Temp/v_0/main.01JSE8KMQVRCSRQAW4QH7519FF.tmp.c:5852: error: expected struct or union but not 'struct main__IGameObject *'
...
cc: C:/Users/info/AppData/Local/Temp/v_0/main.01JSE8KMQVRCSRQAW4QH7519FF.tmp.c:5852: error: expected struct or union but not 'struct main__IGameObject *'
(note: the original output was 3 lines long; it was truncated to its first 2 lines + the last line)
=================================================================
(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?

no c error

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

Option TypeBugs/feature requests, that are related to `?Type`.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Unit: cgenBugs/feature requests, that are related to the default C generating backend.

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