Skip to content

Commit 947adca

Browse files
committed
gopls/internal/lsp/source/methodsets: comparable also has no package
Fix a crash where "error" is assumed to be the only named type with no package. Fixes golang/go#60544 Change-Id: I911296936f93429c780761979aeba38936b14428 Reviewed-on: https://go-review.googlesource.com/c/tools/+/499196 Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent c35c44f commit 947adca

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

gopls/internal/lsp/source/methodsets/methodsets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ func fingerprint(method *types.Func) (string, bool) {
351351
if tname.Pkg() != nil {
352352
buf.WriteString(strconv.Quote(tname.Pkg().Path()))
353353
buf.WriteByte('.')
354-
} else if tname.Name() != "error" {
355-
panic(tname) // error is the only named type with no package
354+
} else if tname.Name() != "error" && tname.Name() != "comparable" {
355+
panic(tname) // error and comparable the only named types with no package
356356
}
357357
buf.WriteString(tname.Name())
358358

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This test exercises a crash due to treatment of "comparable" in methodset
2+
calculation (golang/go#60544).
3+
4+
-min_go is 1.19 as the error message changed at this Go version.
5+
-- flags --
6+
-min_go=go1.19
7+
8+
-- main.go --
9+
package main
10+
11+
type X struct{}
12+
13+
func (X) test(x comparable) {} //@diag("comparable", re"outside a type constraint")

0 commit comments

Comments
 (0)