On Thu, Dec 19, 2019 at 4:42 PM Victor Giordano <vitucho3...@gmail.com> wrote:
>
> Hello guys, just wanna clarify if the words "Untyped nil" refers to the nil 
> value placed literally within a expresion, instead of being placed "behind" a 
> variable, a constanst or a function call return value. So basically, can i 
> say (in a classroom) that untyped nil means literal nil?
> Is that correct?

I wouldn't say that they are exactly the same.  Go supports untyped
constants, as described at https://golang.org/blog/constants.  The
predeclared identifier "nil" is similar to an untyped constant, except
that it doesn't have a default type.  If you write "var a *byte = nil"
then the "nil" acquires the type "*byte" from context.  But if you
write "var a = nil" then there is type in context.  Since "nil"
doesn't have a default type, the case "var a = nil" is a use of an
untyped nil, which is an error.

So an untyped nil is the use of a literal nil when there is no type context.

Ian

-- 
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/CAOyqgcXv8puXkY%2BC3R_GJG6ZcNo_%2BNJuv5bPhvsn0LGr_0Wpjg%40mail.gmail.com.

Reply via email to