Unused variable error when using struct in a loop #22

Closed
opened 2025-08-22 20:19:29 +00:00 by Furkan · 1 comment

Error:

main.q:15:3

    var.x += 1
    ┬
    ╰─ Unused value 'var.x += 1'

Code:

import io

Test {
	x int
}

main() {
	var := Test{
		x : 2 // Changing this to 0 makes it work
	}

	loop 0..10 {
		io.writeInt(var.x)

		var.x += 1
	}
}

Note: using x instead of test.x makes the code work it has to do something with structs

### Error: ``` main.q:15:3 var.x += 1 ┬ ╰─ Unused value 'var.x += 1' ``` --- ### Code: ``` import io Test { x int } main() { var := Test{ x : 2 // Changing this to 0 makes it work } loop 0..10 { io.writeInt(var.x) var.x += 1 } } ``` Note: using x instead of test.x makes the code work it has to do something with structs
ed self-assigned this 2025-08-23 05:41:37 +00:00
Owner
Fixed in https://git.urbach.dev/cli/q/commit/f2da14fb4582995ac6933b3d8ef247228bb4f216. Test is [loop-modify-struct.q](https://git.urbach.dev/cli/q/src/branch/main/tests/loop-modify-struct.q).
ed added spent time 2025-08-25 06:59:15 +00:00
1 hour
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Total time spent: 1 hour
ed
1 hour
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cli/q#22
No description provided.