#Returning pointer to generic struct
33 messages · Page 1 of 1 (latest)
could you explain a bit more about how you came to the conclusion that it's returning nil?
I tried to call a function on it and it was nil
what specifically was nil? it's hard to say with only that much information. there are other things that could have gone wrong, and at this point that's an unknown unknown
can you show a specific call where actually running NewBuffer(…) == nil evaluates to true?
t := NewBuffer[int](10)
t == nil
works fine
actually running it 🙂
not just assuming so
I am running it
that code doesn't compile (and you sent it just a few seconds after i asked), so it doesn't seem like it to me
That's an example of how I am calling it
I know the second line wouldn't compile
i'm not trying to be difficult, but it really seems like something else is going wrong. the premise of your original question—that NewBuffer returns nil—just isn't possible with what you're showing.
if you can provide a more complete, runnable example that reproduces this that would be great.
at some point whatever you are checking is set to nil or never set to anything other than nil but using your constructor function, everything works as expected.
well, the second line might not compile because it does not make sense, as you are not doing anything with the bool value of that statement.
assign it to a variable and print it
I did
2023/07/29 04:00:57 t &{[0 0 0 0 0 0 0 0 0 0] 0 10 0 0}
2023/07/29 04:00:57 &{<nil> <nil> <nil> <nil> <nil> 0 0}
panic: runtime error: invalid memory address or nil pointer dereference
This doesn't happen on go playground
https://goplay.tools/snippet/GqDQtS07Do8
Better Go Playground with syntax highlight support
can you paste it into the go playground
I'm on my phone
and that website is awful on my phone :/
Like honestly that's all I'm testing with
here you have two output lines which does not match the code provided
It works now