Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types, types2: missing error for conflicting method types due to incremental unification #50704

Closed
findleyr opened this issue Jan 19, 2022 · 1 comment
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@findleyr
Copy link
Contributor

findleyr commented Jan 19, 2022

The following code type-checks, but probably shouldn't.

package p

import "fmt"

type C[T any] interface {
	m(T)
	n(T)
}

type Interface interface {
	m(int)
	n(string)
}

func F[T any](t C[T]) {
	switch t.(type) {
	case Interface:
		fmt.Println("here")
	}
}

func main() {
	F[int](nil)
}

(note that there is no instantiation of C that has different argument types for m and n). The reason for this is that the MissingMethod API (used internally for interface assertions) unifies individual methods separately, not the entire method set.

Discovered while looking into #50658.

CC @griesemer

@findleyr findleyr added this to the Go1.18 milestone Jan 19, 2022
@findleyr findleyr added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jan 19, 2022
@griesemer griesemer self-assigned this Jan 19, 2022
@findleyr
Copy link
Contributor Author

Actually, my initial diagnosis may have been wrong. It appears we are far more permissive than I assumed, and the unification logic in missingMethod exists only for method type parameters (which are currently disallowed anyway).

So this is probably fine as-is, though we could be more precise.

@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

3 participants