From e4cfa2f6dad8c73e98a4149948ded424df9c8501 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 9 Aug 2021 10:53:43 -0700 Subject: [dev.typeparams] cmd/compile/internal/types2: parameterized functions must have a body Add the respective check and add missing bodies to tests. Use {} as body for functions that don't return a result. Use { panic(0) } as body for functions that return a result. For #47069. Change-Id: Ia5d7525c9c036baf8a955d13bff448401e08235e Reviewed-on: https://go-review.googlesource.com/c/go/+/340911 Trust: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley --- test/typeparam/smoketest.go | 6 +++--- test/typeparam/tparam1.go | 14 +++++++------- test/typeparam/typelist.go | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/typeparam/smoketest.go b/test/typeparam/smoketest.go index eeda25964f..5243dc5c3c 100644 --- a/test/typeparam/smoketest.go +++ b/test/typeparam/smoketest.go @@ -9,9 +9,9 @@ package smoketest // type parameters for functions -func f1[P any]() -func f2[P1, P2 any, P3 any]() -func f3[P interface{}](x P, y T1[int]) +func f1[P any]() {} +func f2[P1, P2 any, P3 any]() {} +func f3[P interface{}](x P, y T1[int]) {} // function instantiations var _ = f1[int] diff --git a/test/typeparam/tparam1.go b/test/typeparam/tparam1.go index a196caf976..698877a6f0 100644 --- a/test/typeparam/tparam1.go +++ b/test/typeparam/tparam1.go @@ -24,17 +24,17 @@ type ( _[T1, T2 any, T3 any] struct{} ) -func _[T any]() -func _[T, T any]() // ERROR "T redeclared" -func _[T1, T2 any](x T1) T2 +func _[T any]() {} +func _[T, T any]() {} // ERROR "T redeclared" +func _[T1, T2 any](x T1) T2 { panic(0) } // Type parameters are visible from opening [ to end of function. type C interface{} -func _[T interface{}]() -func _[T C]() -func _[T struct{}]() // ERROR "not an interface" -func _[T interface{ m() T }]() +func _[T interface{}]() {} +func _[T C]() {} +func _[T struct{}]() {}// ERROR "not an interface" +func _[T interface{ m() T }]() {} func _[T1 interface{ m() T2 }, T2 interface{ m() T1 }]() { var _ T1 } diff --git a/test/typeparam/typelist.go b/test/typeparam/typelist.go index a68ae1b5cd..5ba14261ab 100644 --- a/test/typeparam/typelist.go +++ b/test/typeparam/typelist.go @@ -85,7 +85,7 @@ func f1x() { } */ -func f2[A any, B interface{ type []A }](_ A, _ B) +func f2[A any, B interface{ type []A }](_ A, _ B) {} func f2x() { f := f2[byte] f(byte(0), []byte{}) @@ -105,7 +105,7 @@ func f3x() { } */ -func f4[A any, B interface{ type []C }, C interface{ type *A }](_ A, _ B, c C) +func f4[A any, B interface{ type []C }, C interface{ type *A }](_ A, _ B, c C) {} func f4x() { f := f4[int] var x int @@ -118,14 +118,14 @@ func f5[A interface { b B c C } -}, B any, C interface{ type *B }](x B) A +}, B any, C interface{ type *B }](x B) A { panic(0) } func f5x() { x := f5(1.2) var _ float64 = x.b var _ float64 = *x.c } -func f6[A any, B interface{ type struct{ f []A } }](B) A +func f6[A any, B interface{ type struct{ f []A } }](B) A { panic(0) } func f6x() { x := f6(struct{ f []string }{}) var _ string = x -- cgit v1.2.3-54-g00ecf