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

incorrect final expression error in or block with if/else statement #23416

Open
islonely opened this issue Jan 9, 2025 · 0 comments
Open

incorrect final expression error in or block with if/else statement #23416

islonely opened this issue Jan 9, 2025 · 0 comments
Labels
Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@islonely
Copy link
Contributor

islonely commented Jan 9, 2025

V version: V 0.4.9 0c9d076, press to see full `v doctor` output
V full version V 0.4.9 4225a34.0c9d076
OS macos, macOS, 15.1.1, 24B91
Processor 8 cpus, 64bit, little endian, Apple M3
Memory 0.16GB/16GB
V executable /Users/adamoates/v/v
V last modified time 2025-01-06 17:09:50
V home dir OK, value: /Users/adamoates/v
VMODULES OK, value: /Users/adamoates/.vmodules
VTMP OK, value: /tmp/v_501
Current working dir OK, value: /Users/adamoates/Documents/shattlebip
Git version git version 2.39.5 (Apple Git-154)
V git status weekly.2024.53-45-g0c9d0762 (10 commit(s) behind V master)
.git/config present true
cc version Apple clang version 16.0.0 (clang-1600.0.26.4)
gcc version Apple clang version 16.0.0 (clang-1600.0.26.4)
clang version Apple clang version 16.0.0 (clang-1600.0.26.4)
tcc version tcc version 0.9.28rc 2024-02-05 HEAD@105d70f7 (AArch64 Darwin)
tcc git status thirdparty-macos-arm64 713692d4
emcc version N/A
glibc version N/A

What did you do?
./v -g -o vdbg cmd/v && ./vdbg /Users/adamoates/Documents/v_tests/test.v && /Users/adamoates/Documents/v_tests/test

fn main() {
	_ := foo() or {
		if err.code() == 1 {
			println('code 1')
		} else {
			println('code other')
		}
		return
	}
}

fn foo() !int {
	return error('foo error')
}

What did you see?

/Users/adamoates/Documents/v_tests/test.v:4:4: error: the final expression in `if` or `match`, must have a value of a non-void type
    2 |     _ := foo() or {
    3 |         if err.code() == 1 {
    4 |             println('code 1')
      |             ~~~~~~~~~~~~~~~~~
    5 |         } else {
    6 |             println('code other')
/Users/adamoates/Documents/v_tests/test.v:6:4: error: the final expression in `if` or `match`, must have a value of a non-void type
    4 |             println('code 1')
    5 |         } else {
    6 |             println('code other')
      |             ~~~~~~~~~~~~~~~~~~~~~
    7 |         }
    8 |         return

What did you expect to see?

Expected code to compile and print "code other". No value is necessary since we return at the end of the or block. If you remove the else section it compiles fine with just the if statement.

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.

@felipensp felipensp added the Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

No branches or pull requests

2 participants