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 gen error when spawning function with mutable type #19425

Closed
CG-SS opened this issue Sep 23, 2023 · 0 comments · Fixed by #20241
Closed

C gen error when spawning function with mutable type #19425

CG-SS opened this issue Sep 23, 2023 · 0 comments · Fixed by #20241
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@CG-SS
Copy link

CG-SS commented Sep 23, 2023

Describe the bug

I wasn't fully able to find exactly the reason the C gen errors, so apologies if the title is incorrect. But basically, the V code on the reproduction steps generated a C gen error.

Reproduction Steps

Try to compile the following code:

module main

import time
import io
import os

interface Message {
	a int
}

struct Impl {
	a int
}

type HookFunc = fn (Message) ?Message

struct TestStruct {
	fns []HookFunc
}

fn (ts TestStruct) run(mut writer io.Writer) {
	spawn handle_fns(ts.fns, mut writer)
}

fn handle_fns(fns []HookFunc, mut writer io.Writer) {
	mut message := Message(Impl{a: 1})
	for f in fns {
		message = f(message) or { continue }
	}
	println(message)
}

fn main() {
	stack := TestStruct{
		fns: [
			fn (m Message) ?Message {
				return Message(Impl{a: m.a + 1})
			},
			fn (m Message) ?Message {
				return none
			}
		]
	}
	stack.run(mut os.stdout())
	time.sleep(2 * time.second)
}

Expected Behavior

Should compile and print:

Message(Impl{
    a: 2
})

Current Behavior

Fails to C gen

Possible Solution

No response

Additional Information/Context

It seems that the presence of a mutable io.Writer influences the C code generation.

V version

V 0.4.1 1c9ab77

Environment details (OS name and version, etc.)

V full version: V 0.4.1 1c9ab77
OS: linux, Linux version 6.4.12-200.fc38.x86_64 (mockbuild@30894952d3244f1ab967aeda9ed417f6) (gcc (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1), GNU ld version 2.39-9.fc38) #1 SMP PREEMPT_DYNAMIC Wed Aug 23 17:46:49 UTC 2023
Processor: 64 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz

getwd: /home/shockwave-1
vexe: /home/shockwave-1/v/v
vexe mtime: 2023-09-23 15:26:12

vroot: OK, value: /home/shockwave-1/v
VMODULES: OK, value: /home/shockwave-1/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.41.0
Git vroot status: weekly.2023.38-5-g77219de1
.git/config present: true

CC version: cc (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1)
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

Important

You can vote for this issue using the 👍 reaction. More votes increase the issue's priority
for developers.

Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.

@CG-SS CG-SS added the Bug This tag is applied to issues which reports bugs. label Sep 23, 2023
@ArtemkaKun ArtemkaKun added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Sep 24, 2023
shove70 added a commit to shove70/v that referenced this issue Dec 21, 2023
spytheman pushed a commit that referenced this issue Dec 22, 2023
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. 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