Skip to content

if mut: optional mut after an if check it's not mutable #24692

Description

@esquerbatua

Describe the bug

Modify an option after checks if it's different of none

Reproduction Steps

fn main() {
	mut option_1 := ?int(10)
	if option_1 != none {
		option_1 = 11
	}

    println('Options: ${option_1}')
}

Expected Behavior

Prints: Options: 11

Current Behavior

.v:21:3: error: `option_1` is immutable, declare it with `mut` to make it mutable
   19 |     mut option_1 := ?int(10)
   20 |     if option_1 != none {
   21 |         option_1 = 10
      |         ~~~~~~~~
   22 |     }
   23 |

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.10 8320da2.f250636

Environment details (OS name and version, etc.)

V full version V 0.4.10 8320da2.f250636
OS linux, Ubuntu 24.04.2 LTS
Processor 16 cpus, 64bit, little endian, AMD Ryzen 7 7840HS w/ Radeon 780M Graphics
Memory 47.46GB/86.23GB
V executable /home/esquerbatua/git/v/v
V last modified time 2025-06-10 17:25:18
V home dir OK, value: /home/esquerbatua/git/v
VMODULES OK, value: /home/esquerbatua/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/esquerbatua/git/breakV
Git version git version 2.43.0
V git status weekly.2025.16-285-gf2506368
.git/config present true
cc version cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
gcc version gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
clang version N/A
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.39-0ubuntu8.4) 2.39

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Unit: CheckerBugs/feature requests, that are related to the type checker.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions