Skip to content

C error on arr.last() as Type inside anon fn #23530

Description

@islonely
V version: V 0.4.9 f9d3bd3, press to see full `v doctor` output
V full version V 0.4.9 4225a34.f9d3bd3
OS macos, macOS, 15.2, 24C101
Processor 8 cpus, 64bit, little endian, Apple M3
Memory 0.48GB/16GB
V executable /Users/adamoates/v/v
V last modified time 2025-01-19 21:19:31
V home dir OK, value: /Users/adamoates/v
VMODULES OK, value: /Users/adamoates/.vmodules
VTMP OK, value: /tmp/v_501
Current working dir OK, value: /Users/adamoates/repos/cyberian_tiger
Git version git version 2.39.5 (Apple Git-154)
V git status weekly.2025.03-5-gf9d3bd39
.git/config present true
cc version Apple clang version 16.0.0 (clang-1600.0.26.6)
gcc version Apple clang version 16.0.0 (clang-1600.0.26.6)
clang version Apple clang version 16.0.0 (clang-1600.0.26.6)
tcc version tcc version 0.9.28rc 2024-02-05 HEAD@105d70f7 (AArch64 Darwin)
tcc git status thirdparty-macos-arm64 713692d4
emcc version N/A
glibc version N/A

What did you do?
./v -g -o vdbg cmd/v && ./vdbg /Users/adamoates/Documents/test.v && /Users/adamoates/Documents/test

@[heap]
struct Foo {
mut:
	val int
}

@[heap]
struct Bar {
mut:
	val int
}

interface FooBar {
mut:
	val int
}

fn main() {
	mut fbs := []&FooBar{}
	fbs << &Foo{1}
	do_something := fn [mut fbs] () {
		_ := fbs.last() as Foo // this line works outside of anon fn
	}
	do_something()
}

What did you see?

================== C compilation error (from cc): ==============
cc: /tmp/v_501/test.01JJ070E9Q2AMPY8P60M3QA2DT.tmp.c:1901:131: error: call to undeclared function 'v_typeof_interface_idx_main__FooBar'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
cc:  1901 |         {main__Foo _ = ({ main__FooBar* _t1 = (*(main__FooBar**)array_last(_V_closure_ctx->fbs)); *(main__Foo*)__as_cast(_t1->_main__Foo,v_typeof_interface_idx_main__FooBar(_t1->_typ), 103); });}
cc:       |                                                                                                                                          ^
cc: /tmp/v_501/test.01JJ070E9Q2AMPY8P60M3QA2DT.tmp.c:1901:131: note: did you mean 'v_typeof_interface_main__FooBar'?
cc: /tmp/v_501/test.01JJ070E9Q2AMPY8P60M3QA2DT.tmp.c:1131:15: note: 'v_typeof_interface_main__FooBar' declared here
cc:  1131 | static char * v_typeof_interface_main__FooBar(int sidx);
cc:       |               ^
cc: 1 error 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?

Expected code to compile.

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

No labels
No labels

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