Unused value 'false' #34

Closed
opened 2025-09-08 21:19:30 +00:00 by Furkan · 2 comments

Error

main.q:5:15

    is_sorted := false
                 ┬
                 ╰─ Unused value 'false'

Code

import io
import mem

buble_sort(arr *uint8) {
	is_sorted := false

	loop {
		is_sorted = true

		loop i := 0..7 {
			if arr[i] > arr[i + 1] {
				temp := arr[i]
				arr[i] = arr[i + 1]
				arr[i + 1] = temp
				is_sorted = false
			}
		}

		if is_sorted {
			return
		}
	}
}

main() {
	arr := mem.alloc(8)

	arr[0] = 'h'
	arr[1] = 'g'
	arr[2] = 'f'
	arr[3] = 'e'
	arr[4] = 'd'
	arr[5] = 'c'
	arr[6] = 'b'
	arr[7] = 'a'

	buble_sort(arr.ptr) // Can't pass as a string bc of immutability

	io.write(arr)
	mem.free(arr)
}

Error ``` main.q:5:15 is_sorted := false ┬ ╰─ Unused value 'false' ``` Code ``` import io import mem buble_sort(arr *uint8) { is_sorted := false loop { is_sorted = true loop i := 0..7 { if arr[i] > arr[i + 1] { temp := arr[i] arr[i] = arr[i + 1] arr[i + 1] = temp is_sorted = false } } if is_sorted { return } } } main() { arr := mem.alloc(8) arr[0] = 'h' arr[1] = 'g' arr[2] = 'f' arr[3] = 'e' arr[4] = 'd' arr[5] = 'c' arr[6] = 'b' arr[7] = 'a' buble_sort(arr.ptr) // Can't pass as a string bc of immutability io.write(arr) mem.free(arr) } ```
ed changed title from Unused variable error to Unused value 'false' 2025-09-09 07:32:50 +00:00
Owner

This is not a bug. The false value really is never used anywhere.
That's the static analysis making you aware of dead code.

You can fix it by defining is_sorted within the loop using true as the initial value:

is_sorted := true
This is not a bug. The `false` value really is never used anywhere. That's the static analysis making you aware of dead code. You can fix it by defining `is_sorted` within the loop using `true` as the initial value: ``` is_sorted := true ```
Author

Its really funny dead code elimination outsmarted me here. Closing the issue

Its really funny dead code elimination outsmarted me here. Closing the issue
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
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#34
No description provided.