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

Default generic value T{} is not recognized in if condition #22677

Closed
avitkauskas opened this issue Oct 27, 2024 · 2 comments · Fixed by #22682
Closed

Default generic value T{} is not recognized in if condition #22677

avitkauskas opened this issue Oct 27, 2024 · 2 comments · Fixed by #22682
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones). Unit: vfmt Bugs/feature requests, that are related to the `vfmt`, the formatter for V.

Comments

@avitkauskas
Copy link
Contributor

avitkauskas commented Oct 27, 2024

Describe the bug

in if e != T{} {...} T{} is formatted wrongly by the formatter and does not complile.

Reproduction Steps

struct St[T] {
mut:
	a T
}

fn (mut s St[T]) f(e T) {
        // notice the wrong formatting of `if e != T{}`
	if e != T{
        }
	{
		s.a = e
	}
}

fn main() {
	mut s := St[int]{}
	s.f(1)
}

Expected Behavior

It should be left formatted as if e != T{} and it should format.

Current Behavior

bug2.v:7:10: error: undefined ident: T
5 |
6 | fn (mut s St[T]) f(e T) {
7 | if e != T {
| ^
8 | }
9 | {
bug2.v:7:5: error: non-bool type void used as if condition
5 |
6 | fn (mut s St[T]) f(e T) {
7 | if e != T {
| ~~~~~~
8 | }
9 | {

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 8ffcc34

Environment details (OS name and version, etc.)

macOS

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.

@avitkauskas avitkauskas added the Bug This tag is applied to issues which reports bugs. label Oct 27, 2024
@spytheman spytheman added Unit: vfmt Bugs/feature requests, that are related to the `vfmt`, the formatter for V. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones). Generics[T] Bugs/feature requests, that are related to the V generics. labels Oct 28, 2024
@felipensp felipensp self-assigned this Oct 28, 2024
@avitkauskas
Copy link
Contributor Author

I confirm this is fixed by #22682.

@felipensp
Copy link
Member

Thanks for testing @avitkauskas

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. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones). Unit: vfmt Bugs/feature requests, that are related to the `vfmt`, the formatter for V.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants