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 while trying to map it.wait() on a thread of arrays #21049

Closed
not-ivy opened this issue Mar 17, 2024 · 6 comments · Fixed by #21055
Closed

c error while trying to map it.wait() on a thread of arrays #21049

not-ivy opened this issue Mar 17, 2024 · 6 comments · Fixed by #21055
Assignees
Labels
Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@not-ivy
Copy link

not-ivy commented Mar 17, 2024

V doctor:

V full version: V 0.4.4 ac2dcc2
OS: linux, "Arch Linux"
Processor: 16 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i7-1260P

getwd: /home/nora/Documents/foxglove-world/fox
vexe: /usr/lib/vlang/v
vexe mtime: 2024-03-16 22:23:00

vroot: NOT writable, value: /usr/lib/vlang
VMODULES: OK, value: /home/nora/.vmodules
VTMP: OK, value: /tmp/v_60271

Git version: git version 2.44.0
Git vroot status: Error: fatal: not a git repository (or any of the parent directories): .git
.git/config present: false

CC version: cc (GCC) 13.2.1 20230801
thirdparty/tcc: N/A

What did you do?
v run .

module cmds

import os
import cli
import net.urllib

pub fn sync() cli.Command {
	return cli.Command{
		name: 'sync'
		description: 'sync local dens from remote'
		execute: execsync
	}
}

fn execsync(cmd cli.Command) ! {
	dens := os.read_lines('/etc/fox/dens')!.map(urllib.parse(it)!)
	mut threads := []thread !{}
	for den in dens {
		threads << spawn update(den)
	}
	threads.map(it.wait()!)
}

fn update(den urllib.URL) ! {
	println(den.str())
	return
}

What did you expect to see?

code works as expected

What did you see instead?

==================
/tmp/v_60271/fox.6109388202681245468.tmp.c:24611: error: declaration of void object
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

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.

@not-ivy
Copy link
Author

not-ivy commented Mar 17, 2024

using regular for..in loop works fine, like the following

fn execsync(cmd cli.Command) ! {
	dens := os.read_lines('/etc/fox/dens')!.map(urllib.parse(it)!)
	mut threads := []thread !{}
	for den in dens {
		threads << spawn update(den)
	}
	for t in threads {
		t.wait()!
	}
}

@felipensp
Copy link
Member

It looks like the issue treated in the PR #21011 @Delta456

@felipensp felipensp added the Unit: Checker Bugs/feature requests, that are related to the type checker. label Mar 17, 2024
@not-ivy
Copy link
Author

not-ivy commented Mar 17, 2024

still reproducible on bedaf4f

$ v version
V 0.4.4 bedaf4f
$ v run .
==================
/tmp/v_60271/fox.01HS74DVJRND7H5QXD8NTT79NT.tmp.c:25208: error: declaration of void object
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

@Delta456
Copy link
Member

It looks like the issue treated in the PR #21011 @Delta456

My PR handles for ast.LambdaExpr

@Delta456
Copy link
Member

I assume this should be a checker error because Result needs an or value right? @felipensp

@JalonSolov
Copy link
Contributor

Yes. Since Result type can be no return at all, it cannot work in .map() calls. Just like the other error where someone was trying to use .map(println('something')). That one was easier to see, but it's the same type of problem - if there's no return value (which there isn't if an error happens), then you can't use it in .map().

The only way to do this is to force a valid type using an or block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants