Skip to content

error if guard condition expression is illegal for variable with Option type #17460

@i582

Description

@i582

Describe the bug

See code: https://play.vlang.io/p/8946312342

struct Foo {
	name ?string
}

foo := Foo{}
other := foo.name

if name := other {
	println("with name")
} else {
	println("without name")
}

println(foo.name)

Expected Behavior

No error

Current Behavior

Error:

code.v:8:12: error: if guard condition expression is illegal, it should return an option
    6 | other := foo.name
    7 | 
    8 | if name := other {
      |            ~~~~~
    9 |     println("with name")
   10 | } else {

Reproduction Steps

Run code above

Possible Solution

No response

Additional Information/Context

No response

V version

0.3.3

Environment details (OS name and version, etc.)

Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Option TypeBugs/feature requests, that are related to `?Type`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions