Interfaces don't contain interfaces

April 25, 2023

As we learned recently, Go interface elements may contain a type term of a non-interface type. It’s worth re-iterating that these are non-interface types.

In particular, as the spec states:

General interfaces

By construction, an interface’s type set never contains an interface type.

That is to say, that the following is invalid:

type interface foo {
  /* some interface elements */
}

type interface bar {
  foo
}

Actually, I lied. That’s not invalid. It’s a case of embedding. But the point is, putting the name of an interface inside of an interface like that does not work as putting the name of a type, such as int or a struct, in an interface.

Quotes from The Go Programming Language Specification Version of December 15, 2022


Share this

Direct to your inbox, daily. I respect your privacy .

Unsure? Browse the archive .

Get daily content like this in your inbox!

Subscribe