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

slice.unique still returns incorrect slice #3769

Closed
skaman opened this issue Jun 16, 2024 · 2 comments
Closed

slice.unique still returns incorrect slice #3769

skaman opened this issue Jun 16, 2024 · 2 comments

Comments

@skaman
Copy link
Contributor

skaman commented Jun 16, 2024

Context

Odin: dev-2024-06-nightly:f745a1c47
OS: Windows 11 Professional (version: 23H2), build 22631.3737
CPU: AMD Ryzen Threadripper 3970X 32-Core Processor
RAM: 65414 MiB
Backend: LLVM 17.0.1

Expected Behavior

Given this example code

tmp := slice.unique([]int{1, 2, 4, 4, 5})
for v, i in tmp {
    fmt.printfln("index: %d, value: %d", i, v)
}

It should output:

index: 0, value: 1
index: 1, value: 2
index: 2, value: 4
index: 3, value: 5

Current Behavior

The output that currently i get is:

index: 0, value: 1
index: 1, value: 4
index: 2, value: 5

Failure Information (for bugs)

I think the bug is related to:

In detail the index i not increase when it's equal with j but it should.

Steps to Reproduce

  1. Paste the example code from "Expected Behavior" into the main proc
  2. Run it
@Kelimion
Copy link
Member

Interesting. The previous fix did indeed fix the examples given there:

	s := []int{2,2,2}
	res := slice.unique(s)
	assert(slice.equal(res,[]int{2}))

	res = slice.unique([]int{1,1,1,2,2,3,3,3,3})
	assert(slice.equal(res, []int{1,2,3}))

	res = slice.unique_proc([]int{1,1,1,2,2,3,3,3,3}, proc(a, b: int) -> bool {
		return a == b
	})
	assert(slice.equal(res, []int{1,2,3}))

But I can also reproduce the bug you found using that old fix.
I'll have a look at your fix momentarily and will write more extensive test coverage for tests/core/slice.

@Kelimion
Copy link
Member

Fixed by #3770.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants