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

C error undeclated function: spawn method with param as interface defined in another module #23471

Closed
jorgeluismireles opened this issue Jan 14, 2025 · 2 comments · Fixed by #23517
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@jorgeluismireles
Copy link

jorgeluismireles commented Jan 14, 2025

Describe the bug

spawn a method with a parameter implementing an interface defined in another module causes C error. Works if

  • we don't call the spawn
  • The interface/struct are local (not in another module).

Reproduction Steps

File bugs/record.v with main:

module main

import records

fn web(recorder records.Recorder) {
	for {
		// web server simulated
	}
}

struct Serial {

}

fn (mut s Serial) write_record(record &records.Record) ! {
	// do something...
	return 
}

fn main() {
	mut s := &Serial{}
	spawn web(s)
}

File bugs/records/record.v

module records

pub interface Recorder {
mut:
	write_record(record &Record) ! 
}

pub struct Record {

}

Expected Behavior

No C error

Current Behavior

$ v -show-c-output run bugs/record.v
======== Output of the C Compiler (/home/jorge/v/thirdparty/tcc/tcc.exe) ========
/tmp/v_1000/record.01JHKAQ154EC1PPEZ27ME0AMY5.tmp.c:1708: error: 'I_main__Serial_to_Interface_recordarg' undeclared
=================================================================================
======== Output of the C Compiler (cc) ========
/tmp/v_1000/record.01JHKAQ154EC1PPEZ27ME0AMY5.tmp.c: In function ‘main__web_thread_wrapper’:
/tmp/v_1000/record.01JHKAQ154EC1PPEZ27ME0AMY5.tmp.c:1708:25: error: ‘I_main__Serial_to_Interface_recordarg’ undeclared (first use in this function); did you mean ‘I_main__Serial_to_Interface_records__Recorder’?
 1708 |         arg->fn(        I_main__Serial_to_Interface_recordarg->arg1__Recorder(arg->arg1));
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                         I_main__Serial_to_Interface_records__Recorder
/tmp/v_1000/record.01JHKAQ154EC1PPEZ27ME0AMY5.tmp.c:1708:25: note: each undeclared identifier is reported only once for each function it appears in
===============================================
No such file or directory; code: 2

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.9 da3112e.9ba294b

Environment details (OS name and version, etc.)

V full version V 0.4.9 da3112e.9ba294b
OS linux, Ubuntu 22.04.5 LTS
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-4150 CPU @ 3.50GHz
Memory 0.58GB/3.7GB
V executable /home/jorge/v/v
V last modified time 2025-01-14 21:00:43
V home dir OK, value: /home/jorge/v
VMODULES OK, value: /home/jorge/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/jorge
Git version git version 2.34.1
V git status weekly.2025.1-51-g9ba294bc
.git/config present true
cc version cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
gcc version gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
clang version Ubuntu clang version 14.0.0-1ubuntu1.1
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9
emcc version emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.5 ()
glibc version ldd (Ubuntu GLIBC 2.35-0ubuntu3.8) 2.35

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.

@jorgeluismireles jorgeluismireles added the Bug This tag is applied to issues which reports bugs. label Jan 14, 2025
Copy link

Connected to Huly®: V_0.6-21901

@jorgeluismireles
Copy link
Author

Workaround, move spawn within web function:

fn web(recorder records.Recorder) {
	spawn fn() {
		for { } // web server here
	}()
}

struct Serial {

}

fn (mut s Serial) write_record(record &records.Record) ! {
	return 
}

fn main() {
	mut s := &Serial{}
	web(s)
	// more calls
	for{ } 
}

@felipensp felipensp self-assigned this Jan 19, 2025
@felipensp felipensp added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants