Forgive me if this has been asked before. I've not been able to find a 
diskussion about it.

A snippet like this

type AppleCount uint32

var i uint32 = 7
var ac AppleCount = i


will fail to compile with an error like:

cannot use i (type uint32) as type AppleCount in assignment


OTOH code like this:

type Dictionary map[string]string
var m map[string]string = make(map[string]string)
var d Dictionary = m


compiles just fine.

There is this about type definitions in The Go Programming Language 
Specification:

*A type definition creates a new, distinct type with the same underlying 
type and operations as the given type, and binds an identifier to it.*

TypeDef = identifier Type .
 
*The new type is called a defined type. It is different from any other 
type, including the type it is created from.*


which I would take to mean that the second snippet should be invalid. 

Is this a bug or 'working as intended'? If it's working as intended, can 
anyone explain the reasoning behind this?

br. Christian Surlykke

-- 
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