Skip to content

Proposal: relaxed rules for assignability with differently-named but identical interfaces #16209

@zellyn

Description

@zellyn

Functions and structures are assignable only when the function arguments or structure fields have identical types. It would be useful to allow assignability in the case where corresponding arguments or fields have identically-shaped interface types.

Passing variables with differently-named but otherwise identical interface types works. However, passing handler functions or structs with such interface types as parameters or fields does not work.

The most important use case is vendoring, where differently-vendored interfaces are common.

Another clear and recent example is renaming: with the moving of context.Context into the standard library, it is impossible to pass a handler function with a context parameter, unless both passing and passed-to code rename at the same time.

Previous informal discussion: https://groups.google.com/forum/#!topic/golang-dev/lOqzH86yAM4

A note: while it would be possible to actually unify identical interfaces, program-wide, I believe it would cause too many problems when using reflection: it would be unclear which name to use.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions