Indeed, zero declaration also works using rsa. prefix.

package main

import (
"crypto/rsa"
"fmt"
// "math/big"
)

func main() {
pub := &rsa.PublicKey{}
mypub := (*rsa.PublicKey)(pub)

fmt.Printf("Hello, playground %v", mypub)
}


On Friday, July 1, 2016 at 4:30:54 PM UTC+2, mura wrote:
>
> Hi,
>
> Thanks for your reply.
>
> FWIW, this code works: https://play.golang.org/p/hcakVsG6qd
>
> So the naming of structs or their field probably doesn't matter.
>
> On Friday, July 1, 2016 at 3:49:11 PM UTC+8, Constantin Konstantinidis 
> wrote:
>>
>> You are redeclaring the package type.
>> When converting type, the conversion semantics is simply mytype(a) and 
>> conversion occurs if the rule that you mention is respected.
>> I suppose that you need to have your own struct to store date, with a 
>> different name everything works.
>> The package type is indeed inaccessible. It is used in the parameter list 
>> of the func that you call.
>>
>> Regards,
>>
>> On Friday, July 1, 2016 at 9:06:30 AM UTC+2, mura wrote:
>>>
>>> Hi all,
>>>
>>> I confronted with a confusing problem regarding struct conversion.
>>>
>>> See https://play.golang.org/p/n6NfjsthHP
>>>
>>> The declarations of PrivateKey and PublicKey are copied from crypto/rsa, 
>>> but the code can not be compiled.
>>> It can be compiled successfully if the embedded field PublicKey is 
>>> replaced with rsa.PublicKey
>>>
>>> According to the spec, two structs are convertible as long as their 
>>> underlying types are identical.
>>>
>>> Is this case my misunderstanding or just a bug (either in the compiler 
>>> or in the spec)?
>>>
>>> mura,
>>>
>>> Thanks
>>>
>>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to