aboutsummaryrefslogtreecommitdiff
path: root/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a
diff options
context:
space:
mode:
Diffstat (limited to 'gopls/internal/lsp/analysis/infertypeargs/testdata/src/a')
-rw-r--r--gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/basic.go20
-rw-r--r--gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/basic.go.golden20
-rw-r--r--gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported.go12
-rw-r--r--gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported.go.golden12
-rw-r--r--gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported/imported.go7
-rw-r--r--gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/notypechange.go26
-rw-r--r--gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/notypechange.go.golden26
7 files changed, 123 insertions, 0 deletions
diff --git a/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/basic.go b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/basic.go
new file mode 100644
index 000000000..1c3d88ba1
--- /dev/null
+++ b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/basic.go
@@ -0,0 +1,20 @@
+// 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 infertyepargs checker.
+
+package a
+
+func f[T any](T) {}
+
+func g[T any]() T { var x T; return x }
+
+func h[P interface{ ~*T }, T any]() {}
+
+func _() {
+ f[string]("hello") // want "unnecessary type arguments"
+ f[int](2) // want "unnecessary type arguments"
+ _ = g[int]()
+ h[*int, int]() // want "unnecessary type arguments"
+}
diff --git a/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/basic.go.golden b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/basic.go.golden
new file mode 100644
index 000000000..72348ff77
--- /dev/null
+++ b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/basic.go.golden
@@ -0,0 +1,20 @@
+// 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 infertyepargs checker.
+
+package a
+
+func f[T any](T) {}
+
+func g[T any]() T { var x T; return x }
+
+func h[P interface{ ~*T }, T any]() {}
+
+func _() {
+ f("hello") // want "unnecessary type arguments"
+ f(2) // want "unnecessary type arguments"
+ _ = g[int]()
+ h[*int]() // want "unnecessary type arguments"
+}
diff --git a/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported.go b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported.go
new file mode 100644
index 000000000..fc1f763df
--- /dev/null
+++ b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported.go
@@ -0,0 +1,12 @@
+// 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
+
+import "a/imported"
+
+func _() {
+ var x int
+ imported.F[int](x) // want "unnecessary type arguments"
+}
diff --git a/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported.go.golden b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported.go.golden
new file mode 100644
index 000000000..6099545bb
--- /dev/null
+++ b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported.go.golden
@@ -0,0 +1,12 @@
+// 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
+
+import "a/imported"
+
+func _() {
+ var x int
+ imported.F(x) // want "unnecessary type arguments"
+}
diff --git a/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported/imported.go b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported/imported.go
new file mode 100644
index 000000000..f0610a8b4
--- /dev/null
+++ b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/imported/imported.go
@@ -0,0 +1,7 @@
+// 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 imported
+
+func F[T any](T) {}
diff --git a/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/notypechange.go b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/notypechange.go
new file mode 100644
index 000000000..c304f1d0d
--- /dev/null
+++ b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/notypechange.go
@@ -0,0 +1,26 @@
+// 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.
+
+// We should not suggest removing type arguments if doing so would change the
+// resulting type.
+
+package a
+
+func id[T any](t T) T { return t }
+
+var _ = id[int](1) // want "unnecessary type arguments"
+var _ = id[string]("foo") // want "unnecessary type arguments"
+var _ = id[int64](2)
+
+func pair[T any](t T) (T, T) { return t, t }
+
+var _, _ = pair[int](3) // want "unnecessary type arguments"
+var _, _ = pair[int64](3)
+
+func noreturn[T any](t T) {}
+
+func _() {
+ noreturn[int64](4)
+ noreturn[int](4) // want "unnecessary type arguments"
+}
diff --git a/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/notypechange.go.golden b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/notypechange.go.golden
new file mode 100644
index 000000000..93c6f707c
--- /dev/null
+++ b/gopls/internal/lsp/analysis/infertypeargs/testdata/src/a/notypechange.go.golden
@@ -0,0 +1,26 @@
+// 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.
+
+// We should not suggest removing type arguments if doing so would change the
+// resulting type.
+
+package a
+
+func id[T any](t T) T { return t }
+
+var _ = id(1) // want "unnecessary type arguments"
+var _ = id("foo") // want "unnecessary type arguments"
+var _ = id[int64](2)
+
+func pair[T any](t T) (T, T) { return t, t }
+
+var _, _ = pair(3) // want "unnecessary type arguments"
+var _, _ = pair[int64](3)
+
+func noreturn[T any](t T) {}
+
+func _() {
+ noreturn[int64](4)
+ noreturn(4) // want "unnecessary type arguments"
+}