Re: [go-nuts] question about runtime design

2019-10-14 Thread Ian Lance Taylor
On Mon, Oct 14, 2019 at 5:53 AM  wrote:
>
> salam. Hi gophers can any one take a look at at this snippet of code
> https://play.golang.org/p/qv0N0EN81tX
> and answer me why should this panic at runtime, and why the compiler
> does not catch this kind of mistakes.

I assume that you are asking why in your code `call(nil)` will panic
at runtime.  That will pass `nil` as the argument to `call`, which
takes an argument of the interface type `is`.  It then tries to invoke
a method on its argument.  When called with `nil`, invoking the method
fails, because there interface is `nil` and there is no method to
call.  So the program crashes.

The compiler doesn't catch this because it's fine for the `call`
function to call a method on its argument, and it's fine to pass `nil`
as the argument to a function that takes a value of interface type.
It's only in combination that these fail.

If that answer doesn't make sense, perhaps you could be more specific.
For example, tell us exactly what code you think the compiler should
catch.

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/CAOyqgcVs4pKg7HeGuyGUr4dd0iM2b459AAGQuW_PYLNP53AkBg%40mail.gmail.com.


[go-nuts] question about runtime design

2019-10-14 Thread awh6al
salam. Hi gophers can any one take a look at at this snippet of code 
https://play.golang.org/p/qv0N0EN81tX 
and answer me why should this panic at runtime, and why the compiler 
does not catch this kind of mistakes.

-- 
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/4afcfd42-72d3-4920-9ea1-df1ae71c5b8f%40googlegroups.com.