Skip to content

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

Closed

Description

@avitkauskas

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.

Activity

  1. added
    BugThis tag is applied to issues which reports bugs.
    on Oct 27, 2024
  2. added
    Unit: vfmtBugs/feature requests, that are related to the `vfmt`, the formatter for V.
    Status: ConfirmedThis bug has been confirmed to be valid by a contributor.
    Unit: ParserBugs/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.
    on Oct 28, 2024
  3. self-assigned this
    on Oct 28, 2024
  4. avitkauskas commented on Oct 28, 2024

    @avitkauskas
    ContributorAuthor

    I confirm this is fixed by #22682.

  5. felipensp commented on Oct 28, 2024

    @felipensp
    Member

    Thanks for testing @avitkauskas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.Generics[T]Bugs/feature requests, that are related to the V generics.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Unit: ParserBugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).Unit: vfmtBugs/feature requests, that are related to the `vfmt`, the formatter for V.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions