Working on Go project In VSCode, I noticed gopls reports a problem which is ok for the compiler.
I extracted a minimal example as follows:
Suppose we have a project with packages foo (file foo.go) and bar (file bar.go).
The package foo exports type constraint A:
// foo.go
package foo
type A comparable
The package bar consumes the constraint A as
// bar.go
package bar
// import "foo"
func F[T foo.A](a T, b T) bool {
return a == b
}
Since the constraint A "inherits" from comparable, the expression a == b is well defined: T is constrained by A which is comparable, hence == is available for values of type T. The compiler is happy with the code.
But VSCode reports a == b as the problem:
invalid operation: a == b (incomparable types in type set)
In editor,

Two observations:
- if the constraint
type A comparable is defined in the package bar, it's ok for gopls – it's an cross-package problem
- if the constraint is defined as
type A = comparable ie. as typedef (not "newtype") in package foo, it's also ok
Working on Go project In VSCode, I noticed gopls reports a problem which is ok for the compiler.
I extracted a minimal example as follows:
Suppose we have a project with packages
foo(filefoo.go) andbar(filebar.go).The package
fooexports type constraintA:The package
barconsumes the constraintAasSince the constraint
A"inherits" fromcomparable, the expressiona == bis well defined:Tis constrained byAwhich is comparable, hence==is available for values of typeT. The compiler is happy with the code.But VSCode reports
a == bas the problem:In editor,

Two observations:
type A comparableis defined in the packagebar, it's ok for gopls – it's an cross-package problemtype A = comparableie. as typedef (not "newtype") in packagefoo, it's also ok