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

Option types in match result in 3 compiler errors. #21077

Closed
Trakis196 opened this issue Mar 22, 2024 · 0 comments · Fixed by #21079
Closed

Option types in match result in 3 compiler errors. #21077

Trakis196 opened this issue Mar 22, 2024 · 0 comments · Fixed by #21079
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: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).

Comments

@Trakis196
Copy link

Trakis196 commented Mar 22, 2024

Describe the bug

Related to #21076. If a sum type has an Option type as one of its types and match over the sum type with the option type as part of the match, then the compiler returns 3 errors about the option type.

Reproduction Steps

vfmt off and vfmt on is to get around #21076

fn main() {
	f := Foo(?Bar(none))
	match f {
		Baz {}
		// vfmt off
		?Bar {}
		// vfmt on
	}
}

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

Expected Behavior

To compile normally

Current Behavior

Returns 3 errors

error: undefined ident: `Bar`
    8 |         Baz {}
    9 |         // vfmt off
   10 |         ?Bar {}
      |          ~~~
   11 |         // vfmt on
   12 |     

error: `Foo` has no variant `void`.
2 possibilities: `?Bar`, `Baz`.
    8 |         Baz {}
    9 |         // vfmt off
   10 |         ?Bar {}
      |          ~~~
   11 |         // vfmt on
   12 |     }

error: match must be exhaustive (add match branches for: `?Bar` or `else {}` at the end)
    5 | fn main() {
    6 |     f := Foo(?Bar(none))
    7 |     match f {
      |     ~~~~~~~~~
    8 |         Baz {}
    9 |         // vfmt off

Possible Solution

No response

Additional Information/Context

No response

V version

V 9d4ec7b

Environment details (OS name and version, etc.)

OS: linux, "Arch Linux"
Processor: 12 cpus, 64bit, little endian, AMD Ryzen 5 3600X 6-Core Processor

vroot: OK
VMODULES: OK
VTMP: OK

Git version: git version 2.44.0
Git vroot status: weekly.2023.45.1-870-g9d4ec7b5
.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 22, 2024
@felipensp felipensp added Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones). Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Mar 22, 2024
@felipensp felipensp self-assigned this Mar 23, 2024
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: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants