Skip to content

cmd/compile: better error message for type arguments used with unsatisfiable constraints (empty type sets) #40350

@komuw

Description

@komuw

What did you do?

Ran this program: https://go2goplay.golang.org/p/S4MLyTi6yA-

package main

import (
	"fmt"
)

type interger32 interface {
	type int32
}

type number interface {
	type float64, int, int32
	interger32
}

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions