Sorry, I included a typo. I have edited my reply below to fix it.

On Tuesday, November 16, 2021 at 8:25:47 PM UTC-7 Kevin Chowski wrote:

> 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 *un*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/8c3f00b5-aa62-417f-becc-3ab5dce6e466n%40googlegroups.com.

Reply via email to