-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/passes/unusedresult: update and add test for typeparams
This CL implements support for setting unused generic funcs via flags. A test for unused results with generics is added. Update golang/go#48704
- Loading branch information
Jack You
committed
Oct 27, 2021
1 parent
9b675d0
commit b7b4d46
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
go/analysis/passes/unusedresult/testdata/src/typeparams/typeparams.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2015 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// | ||
//go:build go1.18 | ||
|
||
package typeparams | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"typeparams/userdefs" | ||
) | ||
|
||
func _[T any]() { | ||
fmt.Errorf("") // want "result of fmt.Errorf call not used" | ||
_ = fmt.Errorf("") | ||
|
||
errors.New("") // want "result of errors.New call not used" | ||
|
||
err := errors.New("") | ||
err.Error() // want `result of \(error\).Error call not used` | ||
|
||
var buf bytes.Buffer | ||
buf.String() // want `result of \(bytes.Buffer\).String call not used` | ||
|
||
fmt.Sprint("") // want "result of fmt.Sprint call not used" | ||
fmt.Sprintf("") // want "result of fmt.Sprintf call not used" | ||
|
||
userdefs.MustUse[int](1) // want "result of typeparams/userdefs.MustUse call not used" | ||
_ = userdefs.MustUse[int](2) | ||
|
||
st := userdefs.ST[int]{X: 1} | ||
st.String() // want `result of \(typeparams/userdefs.ST\[int\]\).String call not used` | ||
} |
19 changes: 19 additions & 0 deletions
19
go/analysis/passes/unusedresult/testdata/src/typeparams/userdefs/userdefs.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2015 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// | ||
//go:build go1.18 | ||
|
||
package userdefs | ||
|
||
func MustUse[T interface{ ~int }](v T) T { | ||
return v + 1 | ||
} | ||
|
||
type ST[T interface{ ~int }] struct { | ||
X T | ||
} | ||
|
||
func (st *ST[T]) String() string { | ||
return "st" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters