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

cannot return an option from function that returns alias to Option as Result #21123

Closed
MCausc78 opened this issue Mar 27, 2024 · 2 comments · Fixed by #21128
Closed

cannot return an option from function that returns alias to Option as Result #21123

MCausc78 opened this issue Mar 27, 2024 · 2 comments · Fixed by #21128
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@MCausc78
Copy link
Contributor

MCausc78 commented Mar 27, 2024

Describe the bug

<title>

Reproduction Steps

struct Foo {
	x int
}

type Bar = ?Foo

enum Baz {
	nothing
	bad
	value
}

fn f(b Baz) !Bar {
	match b {
		.nothing {
			return none
		}
		// .bad { return error('hmm?') }
		.value {
			return Foo{
				x: 42
			}
		}
		else {
			return none
		}
	}
}

fn main() {
}

Expected Behavior

either checker error, or successful compile

Current Behavior

==================
C:/Users/mclr/AppData/Local/Temp/v_0/test.01HT0PV8ZMF3XE50KJ9J44T7RM.tmp.c:6922: warning: implicit declaration of function 'tcc_backtrace'
C:/Users/mclr/AppData/Local/Temp/v_0/test.01HT0PV8ZMF3XE50KJ9J44T7RM.tmp.c:13162: error: cannot convert 'struct _option_main__Foo' to 'struct _result_main__Bar'
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.5 f6a00fa

Environment details (OS name and version, etc.)

V full version: V 0.4.5 57a33c3.f6a00fa
OS: windows, Microsoft Windows 11 Pro v22000 64-bit
Processor: 12 cpus, 64bit, little endian, 

getwd: D:\Games\Proekti\V\interactions
vexe: D:\Games\Proekti\V\v\v.exe
vexe mtime: 2024-03-27 19:39:55

vroot: OK, value: D:\Games\Proekti\V\v
VMODULES: OK, value: C:\Users\mclr\.vmodules
VTMP: OK, value: C:\Users\mclr\AppData\Local\Temp\v_0

Git version: git version 2.37.0.windows.1
Git vroot status: weekly.2024.09-133-gf6a00fa5
.git/config present: true

CC version:
thirdparty/tcc status: thirdparty-windows-amd64 a39eb79b

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.

@MCausc78 MCausc78 added the Bug This tag is applied to issues which reports bugs. label Mar 27, 2024
@Delta456
Copy link
Member

This should be a checker error.

@Delta456 Delta456 self-assigned this Mar 27, 2024
@felipensp felipensp added the Unit: Checker Bugs/feature requests, that are related to the type checker. label Mar 28, 2024
@dumblob
Copy link
Contributor

dumblob commented Jun 1, 2024

Hm, why a checker error?

If I were working e.g. with trees modeled using the Option type and would be passing these trees around in all my functions, then as in any other application, I will have a buch of functions returning some error for which I will want to use the Result type.

How should I write such an app without combining Result and Option? Thoughts @felipensp ?

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. 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