Skip to content

cmd/compile: puzzling "does not satisfy comparable" error message #49112

@ALTree

Description

@ALTree
$ gotip version
go version devel go1.18-9ff91b9098 Fri Oct 22 00:57:18 2021 +0000 windows/amd64
package main

type I interface {
	int
}

func f[G I](g G) {
	println(g)
}

func main() {
	var v1 float64
	var v2 []int
	f(v1)
	f(v2)
}

Building prints:

$ gotip build test.go
# command-line-arguments
.\test.go:14:3: float64 does not satisfy I
.\test.go:15:3: []int does not satisfy comparable

The error message for f(v1) makes sense:

float64 does not satisfy I

but the one for f(v2) is puzzling:

[]int does not satisfy comparable

It mentions the predeclared constraint comparable, but comparable has nothing to do with I. Why?

cc @griesemer @findleyr

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.release-blocker

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions