v icon indicating copy to clipboard operation
v copied to clipboard

Error in return `none` from or block inside `match`

Open impopular-guy opened this issue 1 year ago • 1 comments

Describe the bug

Error in return none from or block inside match. Similar if-else works.

Expected Behavior

run successfully

Current Behavior

examples/check_encode.v:81:26: error: the default expression type in the `or` block should be `int`, instead you gave a value of type `none`
   79 |         0 { 5 }
   80 |         1 { none }
   81 |         else { subfunc(i) or { none } }
      |                                ~~~~
   82 |     }
   83 | }

Reproduction Steps

module main

fn func(i int) ?int {
	return match i {
		0 { 5 }
		1 { none }
		else { subfunc(i) or { none } }
	}
}

fn subfunc(i int) !int {
	if i == 2 {
		return 2
	}
	return error('Subfunc error')
}

fn main() {
	println(func(3))
}

Possible Solution

No response

Additional Information/Context

This works

fn func(i int) ?int {
	if i == 0 {
		return 5
	} else if i == 1 {
		return none
	} else {
		return subfunc(i) or { none }
	}
}

V version

V 0.3.3 9c511e0

Environment details (OS name and version, etc.)

OS: windows, Microsoft Windows 11 Home Single Language v22621 64-bit
Processor: 8 cpus, 64bit, little endian, 
CC version: Error: exec failed (CreateProcess) with code 2: The system cannot find the file specified.
 cmd: cc --version

getwd: C:\Users\dhrit\.vmodules\vbson
vmodules: C:\Users\dhrit\.vmodules
vroot: C:\BIN\v
vexe: C:\BIN\v\v.exe
vexe mtime: 2023-02-26 08:44:50
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.3 9794a23.9c511e0

Git version: git version 2.35.1.windows.2
Git vroot status: weekly.2023.08-30-g9c511e03 (2 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-windows-amd64 1e6e7c6f

impopular-guy avatar Feb 27 '23 10:02 impopular-guy