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

cmd/go2go: unclear error message in embedded type lists #40350

komuw opened this issue Jul 22, 2020 · 1 comment

cmd/go2go: unclear error message in embedded type lists #40350

komuw opened this issue Jul 22, 2020 · 1 comment


Copy link

@komuw komuw commented Jul 22, 2020

What did you do?

Ran this program:

package main

import (

type interger32 interface {
	type int32

type number interface {
	type float64, int, int32

func Largest[type T number](s []T) T {
	var largest T
	for _, v := range s {
		if v > largest {
			largest = v
	return largest

func main() {
	arr := []int{101, -1, 45, 646, 3}
	l := Largest[int](arr)

	fmt.Printf("largest in %v is: %v", arr, l)

What did you expect to see?

  • Either it runs or produces a comprehensible error message about int32 been repeated in interfaces interger32 & number

What did you see instead?

type checking failed for main
prog.go2:28:15: int does not satisfy number (int not found in int32)
Copy link

@griesemer griesemer commented Jul 24, 2020

Just for the record, the problem is not that int32 is repeated in both interfaces, the problem is that int is not repeated in both interfaces: When interfaces are embedded, all the type lists are intersected. This way we can guarantee that if a type T satisfies an interface that embeds an interface E, T also satisfies E.

Agreed that we could use a better error message. Not urgent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants