8000 Handle nil deprecation comments by dajiaohuang · Pull Request #1778 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
5 changes: 4 additions & 1 deletion go/ir/instantiate.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ func createInstance(fn *Function, rtargs, targs []types.Type) *Function {
panic("Instantiate of a Signature returned a non-signature")
}
obj = fn.object // instantiation does not exist yet
sig = prog.canon.Type(instance).(*types.Signature)
// Do not canonicalize signatures here. Receiver types are not part of
// signature identity, so a function signature may otherwise reuse a
// previously canonicalized method signature with a receiver.
sig = instance
}

// Choose strategy (instance or wrapper).
Expand Down
6 changes: 6 additions & 0 deletions internal/passes/buildir/buildir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"golang.org/x/tools/go/analysis/analysistest"
"honnef.co/go/tools/internal/passes/buildir"
"honnef.co/go/tools/internal/xtools-internal/testenv"
)

func Test(t *testing.T) {
Expand All @@ -26,3 +27,8 @@ func Test(t *testing.T) {
}
}
}

func TestGenericMethodValueWithGenericFunction(t *testing.T) {
testenv.NeedsGoCommand1Point(t, 27)
analysistest.Run(t, analysistest.TestData(), buildir.Analyzer, "issue1749")
}
18 changes: 18 additions & 0 deletions internal/passes/buildir/testdata/src/issue1749/issue1749.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package issue1749

type T struct{}

func (T) M[P any]() P {
var zero P
return zero
}

func G[P any]() P {
var zero P
return zero
}

func F(t T) string {
f := t.M[string]
return f() + G[string]()
}
3 changes: 3 additions & 0 deletions internal/xtools-internal/astutil/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
// https://go.dev/wiki/Deprecated, or "" if the documented symbol is not
// deprecated.
func Deprecation(doc *ast.CommentGroup) string {
if doc == nil {
return ""
}
for p := range strings.SplitSeq(doc.Text(), "\n\n") {
// There is still some ambiguity for deprecation message. This function
// only returns the paragraph introduced by "Deprecated: ". More
Expand Down
6 changes: 6 additions & 0 deletions internal/xtools-internal/astutil/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ func fn() { }`
})
}
}

func TestDeprecationNil(t *testing.T) {
if got := astutil.Deprecation(nil); got != "" {
t.Fatalf("Deprecation(nil) = %q, want empty string", got)
}
}
0