Skip to content

C Compilation error : error: variable has incomplete type 'mapnode' (aka 'struct mapnode') #25649

Description

@minitoaster
V version: V 0.4.12, press to see full `v doctor` output
V full version V 0.4.12 420c16e
OS macos, macOS, 15.7.1, 24G231
Processor 8 cpus, 64bit, little endian, Apple M1 Pro
Memory 0.09GB/16GB
V executable /opt/homebrew/Cellar/vlang/0.4.12/libexec/v
V last modified time 2025-09-19 10:36:29
V home dir OK, value: /opt/homebrew/Cellar/vlang/0.4.12/libexec
VMODULES OK, value: /Users//.vmodules
VTMP OK, value: /tmp/v_501
Current working dir OK, value: /Users//Exercism/vlang/linked-list
Git version git version 2.51.0
V git status 4.6.19
.git/config present false
cc version Apple clang version 17.0.0 (clang-1700.0.13.5)
gcc version Apple clang version 17.0.0 (clang-1700.0.13.5)
clang version Apple clang version 17.0.0 (clang-1700.0.13.5)
tcc version N/A
tcc git status N/A
emcc version N/A
glibc version N/A

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

What did you see?

================== C compilation error (from cc): ==============
cc: /tmp/v_501/linked-list.01K92CSBFFER0365V8M5Y8VXYN.tmp.c:1686:37: error: variable has incomplete type 'mapnode' (aka 'struct mapnode')
cc:  1686 |         return ((mapnode*)builtin__memdup(&(mapnode){.children = ((void*)0),.len = 0,.keys = {(string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}},.values = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},}, sizeof(mapnode)));
cc:       |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc: /tmp/v_501/linked-list.01K92CSBFFER0365V8M5Y8VXYN.tmp.c:32:16: note: forward declaration of 'struct mapnode'
cc:    32 | typedef struct mapnode mapnode;
cc:       |                ^
cc: /tmp/v_501/linked-list.01K92CSBFFER0365V8M5Y8VXYN.tmp.c:1686:564: error: invalid application of 'sizeof' to an incomplete type 'mapnode' (aka 'struct mapnode')
cc:  1686 |         return ((mapnode*)builtin__memdup(&(mapnode){.children = ((void*)0),.len = 0,.keys = {(string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}, (string){.str=(byteptr)"", .is_lit=1}},.values = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},}, sizeof(mapnode)));
cc:       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ^     ~~~~~~~~~
cc: /tmp/v_501/linked-list.01K92CSBFFER0365V8M5Y8VXYN.tmp.c:32:16: note: forward declaration of 'struct mapnode'
cc:    32 | typedef struct mapnode mapnode;
cc:       |                ^
cc: 2 errors generated.
================================================================
(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?

Hello, I'm a beginner in Vlang. While training with exercises I stumble upon a weird bug: I should be able to instanciate my struct LinkedList and use struct methods on it but I get a cc compilation error. Do you have an idea of what I'm doing wrong ?
Thanks for your help :)

Code used

struct Node {
	mut: 
		value int
		prev ?&Node
		next ?&Node
}

struct LinkedList {
	mut:
		length int
	 	head ?&Node
}


pub fn (mut l LinkedList) push(value int) {
	mut new_node := &Node{value: value}

	if mut head := l.head {
		for head.next != none {
			if mut head_next := head.next {
				head = head_next
			}
		}
		head.next = new_node
		new_node.prev = head

	} else {
		l.head = new_node
	}
	return
}

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.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Status: Has WorkaroundThis issue has workaround.Unit: markusedBugs/feature requests, that are related to the -skip-unused.

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions