-
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/nilfunc: add typeparams test
testdata/src/typeparams is similar to testdata/src/a but uses type parameters. For golang/go#48704 Change-Id: I2d49190b606d6cdcfe79af5f29bba1117b07b94a Reviewed-on: https://go-review.googlesource.com/c/tools/+/359894 Run-TryBot: Guodong Li <guodongli@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Guodong Li <guodongli@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
- Loading branch information
1 parent
a2be0cd
commit a6c6f4b
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
go/analysis/passes/nilfunc/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,52 @@ | ||
// Copyright 2021 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. | ||
|
||
// This file contains tests for the lostcancel checker. | ||
|
||
//go:build go1.18 | ||
|
||
package typeparams | ||
|
||
func f[P any]() {} | ||
|
||
func g[P1 any, P2 any](x P1) {} | ||
|
||
var f1 = f[int] | ||
|
||
type T1[P any] struct { | ||
f func() P | ||
} | ||
|
||
type T2[P1 any, P2 any] struct { | ||
g func(P1) P2 | ||
} | ||
|
||
func Comparison[P any](f2 func()T1[P]) { | ||
var t1 T1[P] | ||
var t2 T2[P, int] | ||
var fn func() | ||
if fn == nil || f1 == nil || f2 == nil || t1.f == nil || t2.g == nil { | ||
// no error; these func vars or fields may be nil | ||
} | ||
if f[P] == nil { // want "comparison of function f == nil is always false" | ||
panic("can't happen") | ||
} | ||
if f[int] == nil { // want "comparison of function f == nil is always false" | ||
panic("can't happen") | ||
} | ||
if g[P, int] == nil { // want "comparison of function g == nil is always false" | ||
panic("can't happen") | ||
} | ||
} | ||
|
||
func Index[P any](a [](func()P)) { | ||
if a[1] == nil { | ||
// no error | ||
} | ||
var t1 []T1[P] | ||
var t2 [][]T2[P, P] | ||
if t1[1].f == nil || t2[0][1].g == nil { | ||
// no error | ||
} | ||
} |