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

Can't have thread type as result, option, or multi-return. #19281

Closed
islonely opened this issue Sep 6, 2023 · 0 comments
Closed

Can't have thread type as result, option, or multi-return. #19281

islonely opened this issue Sep 6, 2023 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@islonely
Copy link
Contributor

islonely commented Sep 6, 2023

Describe the bug

thread.wait() should be able to return any type a function can return. But results, options, and multi-returns are not allowed types for threads.

Reproduction Steps

struct Foo {
mut:
	tx thread !int
	ty thread ?int
	tz thread (int, int)
}

fn Foo.new() Foo {
	mut foo := Foo{
		tx: spawn x(-1)
		ty: spawn y(-1)
		tz: spawn z(-1)
	}
	return foo
}

fn (mut foo Foo) bar() {
	foo.tx.wait() or {
		// error was returned
		0
	}
	foo.ty.wait() or {
		// none was returned
		0
	}
	a_num, b_num := foo.tz.wait()
}

fn x(x int) !int {
	if x < 0 {
		return error('error')
	}
	return x
}

fn y(y int) ?int {
	if y < 0 {
		return none
	}
	return y
}

fn z(z int) (int, int) {
	return (z, z)
}

fn main() {
	mut foo := Foo.new()
	// do something else with foo while foo
	// continues something() on another thread
	foo.bar()
}

Expected Behavior

Expected code to compile and run.

Current Behavior

Unexpected token error is generated.

C:/Users/imado/Documents/test.v:3:12: error: unexpected token `!`, expecting name
    1 | struct Foo {
    2 | mut:
    3 |     tx thread !int
      |               ^
    4 |     ty thread ?int
    5 |     tz thread (int, int)

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.1 639f128

Environment details (OS name and version, etc.)

V full version: V 0.4.1 639f128
OS: windows, Microsoft Windows 11 Pro v22621 64-bit
Processor: 16 cpus, 64bit, little endian,

getwd: C:\Users\imado\Documents\test
vexe: C:\Users\imado\v\v.exe
vexe mtime: 2023-09-05 17:00:49

vroot: OK, value: C:\Users\imado\v
VMODULES: OK, value: C:\Users\imado.vmodules
VTMP: OK, value: C:\Users\imado\AppData\Local\Temp\v_0

Git version: git version 2.33.1.windows.1
Git vroot status: 0.4.1-10-g639f128c
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.

thirdparty/tcc status: thirdparty-windows-amd64 e90c2620

@islonely islonely added the Bug This tag is applied to issues which reports bugs. label Sep 6, 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.
Projects
None yet
Development

No branches or pull requests

1 participant