Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread Marvin Renich
* d...@veryhaha.com [161013 08:42]: > https://golang.org/ref/spec#Type_assertions > > var x interface{} = 7 // x has dynamic type int and value 7 > i := x.(int) // i has type int and value 7 > > type I interface { m() } > var y I > s := y.(string)// illegal

Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread Konstantin Khomoutov
On Thu, 13 Oct 2016 10:38:16 -0700 (PDT) d...@veryhaha.com wrote: > https://golang.org/ref/spec#Type_assertions > > var x interface{} = 7 // x has dynamic type int and value 7 > i := x.(int) // i has type int and value 7 > > type I interface { m() } > var y I > // illegal: strin

Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread digg
On Friday, October 14, 2016 at 1:33:52 AM UTC+8, di...@veryhaha.com wrote: > > > > On Friday, October 14, 2016 at 1:28:01 AM UTC+8, di...@veryhaha.com wrote: >> >> >> >> On Thursday, October 13, 2016 at 11:22:14 PM UTC+8, Chris Manghane wrote: >>> >>> In that example y is a nil interface value of

Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread digg
On Friday, October 14, 2016 at 1:28:01 AM UTC+8, di...@veryhaha.com wrote: > > > > On Thursday, October 13, 2016 at 11:22:14 PM UTC+8, Chris Manghane wrote: >> >> In that example y is a nil interface value of type l. The last line >> implies that for a type assertion to another interface type, t

Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread digg
On Thursday, October 13, 2016 at 11:22:14 PM UTC+8, Chris Manghane wrote: > > In that example y is a nil interface value of type l. The last line > implies that for a type assertion to another interface type, the operation > will only be possible if the underlying value implements both interfac

Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread digg
On Thursday, October 13, 2016 at 11:22:14 PM UTC+8, Chris Manghane wrote: > > In that example y is a nil interface value of type l. The last line > implies that for a type assertion to another interface type, the operation > will only be possible if the underlying value implements both interfac

Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread 'Chris Manghane' via golang-nuts
In that example y is a nil interface value of type l. The last line implies that for a type assertion to another interface type, the operation will only be possible if the underlying value implements both interfaces. That is, the value must have an m() method as well as all of io.reader methods or

Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread digg
On Thursday, October 13, 2016 at 8:52:14 PM UTC+8, Jan Mercl wrote: > > On Thu, Oct 13, 2016 at 2:42 PM > wrote: > > > I don't understand the comment of the last line. Can someone explain it > for me? > > "r has type io.Reader" means that the type if expr.(T) is T. > > "and y must implement both

Re: [go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread Jan Mercl
On Thu, Oct 13, 2016 at 2:42 PM wrote: > I don't understand the comment of the last line. Can someone explain it for me? "r has type io.Reader" means that the type if expr.(T) is T. "and y must implement both I and io.Reader" y is either nil or it implements I, because that's how it was declar

[go-nuts] don't understand the comment in spec Type assertions section

2016-10-13 Thread digg
https://golang.org/ref/spec#Type_assertions var x interface{} = 7 // x has dynamic type int and value 7 i := x.(int) // i has type int and value 7 type I interface { m() } var y I s := y.(string)// illegal: string does not implement I (missing method m)