[go-nuts] why treat int and []int differently here?

2016-07-16 Thread T L
> package main > > func fi(i int) {} > func fis(is []int) {} > > type TI int > type TIS []int > > func main() { > var ti TI > fi(ti) // cannot use ti (type TI) as type int in argument to fi > > var tis TIS > fis(tis) // no problems! > } > > -- You received this message bec

Re: [go-nuts] why treat int and []int differently here?

2016-07-16 Thread Steven Blenkinsop
You've run into the distinction between named types and unnamed types: https://golang.org/ref/spec#Properties_of_types_and_values int, TI, and TIS are named types. []int is an unnamed type. The rules for assignability say: > A value x is assignable to a variable of type T ("x is assignable to T")

Re: [go-nuts] why treat int and []int differently here?

2016-07-16 Thread 'Axel Wagner' via golang-nuts
This is actually a really good question. To the spec-mobile! https://golang.org/ref/spec#Calls Except for one special case, arguments must be single-valued expressions > assignable to the parameter types of F and are evaluated before the > function is called. Okay, so the arguments must be assi

Re: [go-nuts] why treat int and []int differently here?

2016-07-16 Thread Peter Waller
I had written a response, but was beaten to the punch by Steven and Alex by seconds. I'll just add to what they've said. A surprising fact is that `int` is actually not an unnamed type, it's a pre-declared identifier: https://golang.org/ref/spec#Predeclared_identifiers Here's the (seemingly taut