Skip to content

cmd/compile: surprising behavior for doubly declared methods #66285

@griesemer

Description

@griesemer

Before Go 1.13, it was an error for a method to appear more than once (via embedding) in an interface. For instance, this code produced an error ("duplicate method Read"). With 1.14, such code was permitted.

Similarly, this code also produces the same error under 1.13 as one would expect:

type T interface {
	io.Reader
	Reader
}

type Reader interface {
	Read(p []byte) (n int, err error)
}

However, this code does not:

type T interface {
	io.Reader
	io.Reader
}

The reason is that here the method Read both times is imported (through io.Reader): because the io package is "correct", the imported Read method is "exempt" from the 1.13 version check. This seems odd: even though io is valid, the actual embedding of Read happens in the current package (or file) and thus the 1.13 rules should apply irrespective of where the method came from.

A method's origin package should not matter for the version test, only the (file) version of the source where the embedding happens.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions