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

Wrong behavior of !(Type, ?Type) result tuple #22951

Closed
gechandesu opened this issue Nov 23, 2024 · 2 comments · Fixed by #22964
Closed

Wrong behavior of !(Type, ?Type) result tuple #22951

gechandesu opened this issue Nov 23, 2024 · 2 comments · Fixed by #22964
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. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@gechandesu
Copy link
Contributor

gechandesu commented Nov 23, 2024

Describe the bug

Subject

Reproduction Steps

module main

fn foo(f int) !(int, ?int) {
	if f < 0 {
		return error('f is negative')
	}
	if f > 0 {
		return 1, f
	}
	return 0, none
}

fn main() {
	a, b := foo(-1) or { 2, 2 } // since foo arg is negative int, error must occurs
	c := b as int
	assert a == 2
	assert c == 2

	a2, b2 := foo(0) or { 2, 2 }
	c2 := b2 as int
	assert a2 == 0
	assert c2 == 0

	a3, b3 := foo(1) or { 2, 2 }
	c3 := b3 as int
	assert a3 == 1
	assert c3 == 1
}

Expected Behavior

In shot: all assertions must be passed.

Values listed in or {} must be applied here since foo(-1) raises an error:

a , b := foo(-1) or { 2, 2 }

c := b as int
assert a == 2
assert c == 2

In foo(0) case b must be Option(none):

a , b := foo(0) or { 2, 2 }

c := b as int // Option(none) casts to 0
assert a == 0
assert c == 0

Finally:

a , b := foo(1) or { 2, 2 }

c := b as int
assert a == 1
assert c == 1

Current Behavior

a, b := foo(-1) or { 2, 2 } // since foo arg is negative int, error must occurs
println(a) // output: 2
println(b) // output: Option(none) but Option(2) expected

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 393e4ea

Environment details (OS name and version, etc.)

V full version: V 0.4.8 5ec9bb5.393e4ea
OS: linux, Linux version 6.6.8-arch1-1 (linux@archlinux) (gcc (GCC) 13.2.1 20230801, GNU ld (GNU Binutils) 2.41.0) #1 SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:01:01 +0000
Processor: 16 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i5-1240P

getwd: /home/ge/Code/v/netaddr/issues
vexe: /home/ge/.vlang/v
vexe mtime: 2024-11-23 13:05:19

vroot: OK, value: /home/ge/.vlang
VMODULES: OK, value: /home/ge/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.1
Git vroot status: weekly.2024.47-20-g393e4ea8
.git/config present: true

CC version: cc (GCC) 14.2.1 20240910
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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.

Huly®: V_0.6-21393

@gechandesu gechandesu added the Bug This tag is applied to issues which reports bugs. label Nov 23, 2024
@Delta456
Copy link
Member

!?int doesn't work in the below code, I don't know if !(int, ?int) should work.

fn foo (f int) !?int {
	return 0
}

@JalonSolov
Copy link
Contributor

@Delta456 Delta456 added the Unit: Checker Bugs/feature requests, that are related to the type checker. label Nov 24, 2024
@felipensp felipensp self-assigned this Nov 24, 2024
@felipensp felipensp added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Nov 24, 2024
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. 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