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

c error on unwrap of an option type in a match #21093

Closed
Trakis196 opened this issue Mar 25, 2024 · 2 comments · Fixed by #21101
Closed

c error on unwrap of an option type in a match #21093

Trakis196 opened this issue Mar 25, 2024 · 2 comments · Fixed by #21101
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@Trakis196
Copy link

Trakis196 commented Mar 25, 2024

Describe the bug

Unwrapping an option type using an if statement in a sum type match results in a cannot convert c error.

Reproduction Steps

fn main() {
	f := Foo(Bar{})
	match f {
		?Bar {
			if i := f {
				println(i)
			}
		}
		else {}
	}
}

type Foo = ?Bar | Baz
struct Baz {}
struct Bar {}

Expected Behavior

To compile and print Bar{}.

Current Behavior

results in error: cannot convert 'struct main__Foo' to 'struct _option_main__Bar'

Possible Solution

No response

Additional Information/Context

No response

V version

V 6b23b1d

Environment details (OS name and version, etc.)

V full version: V 0.4.5 9d7fe51.6b23b1d
OS: linux, "Arch Linux"
Processor: 12 cpus, 64bit, little endian, AMD Ryzen 5 3600X 6-Core Processor

vroot: OK
VMODULES: OK
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.44.0
Git vroot status: 0.4.5-19-g6b23b1dd
.git/config present: true

CC version: cc (GCC) 13.2.1 20230801
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

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.

@Trakis196 Trakis196 added the Bug This tag is applied to issues which reports bugs. label Mar 25, 2024
@felipensp
Copy link
Member

felipensp commented Mar 25, 2024

As a workaround you can enclose the ?Bar case code with:

$if f is ?Bar {
 
}

@felipensp felipensp added Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Mar 25, 2024
@felipensp
Copy link
Member

Just noticed that there is more work to do to support option as sumtype... A more complete fix is coming. :-)

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: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants