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

Mutable variable in closure not updating in anonymous function #20102

Closed
lv37 opened this issue Dec 6, 2023 · 1 comment
Closed

Mutable variable in closure not updating in anonymous function #20102

lv37 opened this issue Dec 6, 2023 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@lv37
Copy link
Contributor

lv37 commented Dec 6, 2023

Describe the bug

module main

fn main() {
	mut a := 1
	modify_a := fn [mut a] () {
		a = 2 // warning: unused variable: `a` ??
	}
	modify_a()
	println(a) // It should print `2` but it prints `1`
}

Reproduction Steps

Run the above

Expected Behavior

2

Current Behavior

src/main.v:5:22: warning: unused variable: `a`
    3 | fn main() {
    4 |     mut a := 1
    5 |     modify_a := fn [mut a] () {
      |                         ^
    6 |         a = 2 // warning: unused variable: `a` ????
    7 |     }
1

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.3 09d05bb

Environment details (OS name and version, etc.)

V full version: V 0.4.3 b347f54.09d05bb
OS: linux, Linux version 6.6.3-200.fc39.x86_64 (mockbuild@62256c00a5854842b8d1a622060ebc27) (gcc (GCC) 13.2.1 20231011 (Red Hat 13.2.1-4), GNU ld version 2.40-13.fc39) #1 SMP PREEMPT_DYNAMIC Tue Nov 28 19:11:52 UTC 2023
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz

getwd: /home/user/Projects/v-testing/hypixel
vexe: /home/user/.local/lib/v/v
vexe mtime: 2023-12-06 09:47:42

vroot: OK, value: /home/user/.local/lib/v
VMODULES: OK, value: /home/user/.vmodules
VTMP: OK, value: /tmp/v_1002

Git version: git version 2.43.0
Git vroot status: weekly.2023.48-59-g09d05bb5
.git/config present: true

CC version: cc (GCC) 13.2.1 20231011 (Red Hat 13.2.1-4)
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.

@lv37 lv37 added the Bug This tag is applied to issues which reports bugs. label Dec 6, 2023
@lv37
Copy link
Contributor Author

lv37 commented Dec 6, 2023

@lv37 lv37 closed this as completed Dec 6, 2023
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.
Projects
None yet
Development

No branches or pull requests

1 participant