Incorrect pointer to `interface`
Closed this issue · 9 comments
go-type-to-string/converter.go
Lines 31 to 32 in 810c395
Why?
package main
import (
"fmt"
typetostring "github.com/samber/go-type-to-string"
)
func main() {
type I interface {}
fmt.Println(typetostring.GetType[I]()) // *main.I
fmt.Println(typetostring.GetType[*I]()) // *main.I
fmt.Println(typetostring.GetType[**I]()) // **main.I
}
Without the getInterfaceType
hack, typetostring.GetType[interface{}]()
would return *interface {}
.
This is a know limitation.
If you have a better way to handle this case, I would be very happy to accept your contribution!!
Meant why only for any
What about trim *
for all
return t[1:]
We cannot disable all *
, beucase we need to differentiate *string
et string
.
You can disable the getInterfaceType
hack and iterate with existing unit test.
Not ALL*
, only for interface. when reflect.TypeOf(t) == nil
This behavior wasn't planned, was it?
@d-enk not planned indeed, and it seems that the previous commit changed the behavior
TBH, I have no opinion on this.
About samber/do, I don't think it makes any difference, since any
type is unexpected.
You are confused here
Line 45 in 668e292
After 1.3.0 there will be any
No try to unpack interface (not only any
)
Yes, this is why I listed this in the "not supported yet" section.
I just updated the readme to make it clearer.
OK. I'll add an explanation of reason here too. Just
type I interface {
// ...
}
The same type as any other (in the context of this package)
which has its own name.