On Tue, 4 Apr 2017 07:27:17 -0700
Ian Lance Taylor <[email protected]> wrote:
> >> When you insert a value keyed by S{}, the compiler creates a value
> >> of type I which has S as its dynamic type and S{} as its value.
> >>
> >> The program as speficied panics with
> >
> >
> > Apologies if it wasn't clear from my original email, but I
> > understand why this panics; I further acknowledge the behaviour is
> > consistent with the spec.
> >
> > My question is why something that could be caught at compile time
> > is not caught at compile time:
>
> I suspect mostly because nobody thought of it.
>
> That said, note that this in effect a language change. It is possible
> to construct a program that currently works into a program that after
> this change is made will fail to compile. So while we could make this
> change, it would have to be done by changing the language spec. I
> don't know whether it is worth doing; is it a common problem?
IMO implementing such a compile check would be contrary to the "least
WTF" principle. Imagine something like
type S struct {
f func()
}
func (s S) Impl() {}
func Foo() I {
return S{}
}
m[Foo()] = true
The compiler is able to check at compile time that Foo always returns
values of the dynamic type S but that would unnecessary complicate the
analysis.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.