It's not clear to me what problem you are solving. Can you clarify *why* you want to do this?
For what it's worth, this seems correct to me: a function defined in package X should not be able to access the unexported fields of a struct in package Y. If you embed a 'byte' into a struct, that is an exported field and should not be accessible to other packages. On Tuesday, November 16, 2021 at 3:51:39 PM UTC-7 oxc...@gmail.com wrote: > Hello, my issue is similar to: > > https://stackoverflow.com/questions/38784963/exporting-functions-with-anonymous-struct-as-a-parameter-cannot-use-value-type > > In this particular case, it is fixed by exporting the fields capitalizing > the field name. But, what if the struct fields are also anonymous? > > main.go: > ---------------------------------------------------- > package main > > import "a/b" > > func f(s struct{ byte }) {} > > func main() { > s := struct{ byte }{} > f(s) // This works > b.F(s) // This gives an argument type error > } > ---------------------------------------------------- > > b/b.go: > ---------------------------------------------------- > package b > > func F(c struct{ byte }) { > } > ---------------------------------------------------- > > By building this code, we get the following compiler error: > `cannot use s (type struct { byte }) as type struct { byte } in argument > to b.F` > > In my opinion, it should be allowed to export the unnamed (anonymous) > types so the struct can be used anywhere else. Opinions on this? > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ad8f56b7-92ec-4444-aa1b-97cd1d08dbf1n%40googlegroups.com.