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

or_else not compiling with function returning single bool or ptr value #3942

Closed
2nafish117 opened this issue Jul 19, 2024 · 1 comment
Closed

Comments

@2nafish117
Copy link
Contributor

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Operating System & Odin Version:
  • Please paste odin report output:

Odin: dev-2024-07-nightly:b4ca044
OS: Windows 10 Professional (version: 21H2), build 19044.1766
CPU: AMD Ryzen 9 5950X 16-Core Processor
RAM: 130973 MiB
Backend: LLVM 17.0.1

Expected Behavior

or_else should compile when a function returns a single bool or ptr value

Current Behavior

or_else is not compiling when a function returns a single bool or ptr value

Steps to Reproduce

compile this with odin run .

package main

import "core:fmt"

proc_return_int_bool :: proc() -> (int, bool) {
	return 5, false
}

proc_return_bool :: proc() -> bool {
	return false
}

proc_return_int :: proc() -> int {
	return 69
}

global_thing: int
proc_return_rawptr :: proc() -> rawptr {
	return &global_thing
}

proc_return_int_rawptr :: proc() -> (int, rawptr) {
	return 32, &global_thing
}

main :: proc() {
	// compiles fine
	the_int := proc_return_int_bool() or_else fmt.printfln("proc_return_int_bool() or_else")
	
	// compiles fine
	another_int := proc_return_int_rawptr() or_else fmt.printfln("proc_return_int_rawptr() or_else")

	// does not compile.
	// Error: 'or_else' does not return a value, value is of type rawptr 
	//     proc_return_rawptr() or_else fmt.printfln("proc_return_ ... 
	//     ^~~~~~~~~~~~~~~~~~~^
	// proc_return_rawptr() or_else fmt.printfln("proc_return_rawptr() or_else")

	// does not compile
	// Error: 'or_else' does not return a value, value is of type bool 
	//     proc_return_bool() or_else fmt.printfln("proc_return_bo ... 
	//     ^~~~~~~~~~~~~~~~~^
	// proc_return_bool() or_else fmt.printfln("proc_return_bool() or_else")

	// expected to not compile
	// proc_return_int() or_else fmt.printfln("proc_return_int() or_else")
}
@2nafish117
Copy link
Contributor Author

This is expected behaviour, or_else needs a value to return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant