-
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/ctrlflow: add typeparams test
This CL adds a test for the assign pass that involves use of generics. Updates golang/go#48704 Change-Id: I19d27932f0d326e2456b6714f76de01d46f1b1e3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/357777 Trust: Zvonimir Pavlinovic <zpavlinovic@google.com> Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
- Loading branch information
1 parent
8de2a7f
commit c8ad2e1
Showing
5 changed files
with
131 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
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
64 changes: 64 additions & 0 deletions
64
go/analysis/passes/ctrlflow/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,64 @@ | ||
// 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. | ||
|
||
package a | ||
|
||
// This file tests facts produced by ctrlflow. | ||
|
||
var cond bool | ||
|
||
var funcs = []func(){func() {}} | ||
|
||
func a[A any]() { // want a:"noReturn" | ||
if cond { | ||
funcs[0]() | ||
b[A]() | ||
} else { | ||
for { | ||
} | ||
} | ||
} | ||
|
||
func b[B any]() { // want b:"noReturn" | ||
select {} | ||
} | ||
|
||
func c[A, B any]() { // want c:"noReturn" | ||
if cond { | ||
a[A]() | ||
} else { | ||
d[A, B]() | ||
} | ||
} | ||
|
||
func d[A, B any]() { // want d:"noReturn" | ||
b[B]() | ||
} | ||
|
||
type I[T any] interface { | ||
Id(T) T | ||
} | ||
|
||
func e[T any](i I[T], t T) T { | ||
return i.Id(t) | ||
} | ||
|
||
func k[T any](i I[T], t T) T { // want k:"noReturn" | ||
b[T]() | ||
return i.Id(t) | ||
} | ||
|
||
type T[X any] int | ||
|
||
func (T[X]) method1() { // want method1:"noReturn" | ||
a[X]() | ||
} | ||
|
||
func (T[X]) method2() { // (may return) | ||
if cond { | ||
a[X]() | ||
} else { | ||
funcs[0]() | ||
} | ||
} |