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

Can't return a slice of slices ([][]bool) #346

Closed
moritz157 opened this issue Jan 29, 2024 · 3 comments · Fixed by #351
Closed

Can't return a slice of slices ([][]bool) #346

moritz157 opened this issue Jan 29, 2024 · 3 comments · Fixed by #351

Comments

@moritz157
Copy link

I wanted to pass a slice of slices of boolean values ([][]bool). I would assume that this could simply be done like this:

func GetEmptyMatrix(xSize int, ySize int) [][]bool {
	result := [][]bool{}

	for i := 0; i < xSize; i++ {
		result = append(result, []bool{})
		for j := 0; j < ySize; j++ {
			result[i] = append(result[i], false)
		}
	}

	return result
}

In Python I then simply called the function:

from out import matrix

matrix.GetEmptyMatrix(4,4)

However, this failed with the following error: panic: interface conversion: interface {} is []bool, not *[]bool

Is passing a slice of slices generally not supported or do I have to do it in a different way (like passing a slice of pointers to slices)? If this is supported, I would suggest to maybe add an example for this because as far as I can see, there is none yet. If I'm just doing it wrong, a hint in the right direction would be greatly appreciated :)

@richecr
Copy link
Contributor

richecr commented Feb 1, 2024

This problem has similarities to this.

@rcoreilly
Copy link
Member

I'm assuming this is now fixed by #350 unless someone tells me otherwise. And if someone could write a test to confirm, that would be most appreciated (@EvanOman ?)

@EvanOman
Copy link
Contributor

@rcoreilly No, my previous PR did not fix slices, only maps

However I just added #351 which fixes this issue and adds a test based on the example from @moritz157

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

Successfully merging a pull request may close this issue.

4 participants