From f29abccd8aaadf0297da3947909feca3c8ec31c9 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Thu, 26 Aug 2021 16:20:33 +0800 Subject: [PATCH] test: add test cases for issue47892. This issue has been fixed in https://golang.org/cl/345411 Fixes: #47892 Change-Id: I13dd3814650913da065e5f24a0c61d30adb0633a Reviewed-on: https://go-review.googlesource.com/c/go/+/345229 Reviewed-by: Dan Scales Trust: Dan Scales Trust: Keith Randall Trust: Alberto Donizetti Run-TryBot: Alberto Donizetti TryBot-Result: Go Bot --- test/typeparam/issue47892.dir/a.go | 17 +++++++++++++++ test/typeparam/issue47892.dir/main.go | 21 +++++++++++++++++++ test/typeparam/issue47892.go | 7 +++++++ test/typeparam/issue47892b.dir/a.go | 29 ++++++++++++++++++++++++++ test/typeparam/issue47892b.dir/main.go | 17 +++++++++++++++ test/typeparam/issue47892b.go | 7 +++++++ 6 files changed, 98 insertions(+) create mode 100644 test/typeparam/issue47892.dir/a.go create mode 100644 test/typeparam/issue47892.dir/main.go create mode 100644 test/typeparam/issue47892.go create mode 100644 test/typeparam/issue47892b.dir/a.go create mode 100644 test/typeparam/issue47892b.dir/main.go create mode 100644 test/typeparam/issue47892b.go diff --git a/test/typeparam/issue47892.dir/a.go b/test/typeparam/issue47892.dir/a.go new file mode 100644 index 0000000000..b63d604eeb --- /dev/null +++ b/test/typeparam/issue47892.dir/a.go @@ -0,0 +1,17 @@ +// 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 + +type Index[T any] interface { + G() T +} + +type I1[T any] struct { + a T +} + +func (i *I1[T]) G() T { + return i.a +} diff --git a/test/typeparam/issue47892.dir/main.go b/test/typeparam/issue47892.dir/main.go new file mode 100644 index 0000000000..bd610d4ee6 --- /dev/null +++ b/test/typeparam/issue47892.dir/main.go @@ -0,0 +1,21 @@ +// 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 main + +import "a" + +type Model[T any] struct { + index a.Index[T] +} + +func NewModel[T any](index a.Index[T]) Model[T] { + return Model[T]{ + index: index, + } +} + +func main() { + _ = NewModel[int]((*a.I1[int])(nil)) +} diff --git a/test/typeparam/issue47892.go b/test/typeparam/issue47892.go new file mode 100644 index 0000000000..572f680d3d --- /dev/null +++ b/test/typeparam/issue47892.go @@ -0,0 +1,7 @@ +// rundir -G=3 + +// 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 ignored \ No newline at end of file diff --git a/test/typeparam/issue47892b.dir/a.go b/test/typeparam/issue47892b.dir/a.go new file mode 100644 index 0000000000..5adb492578 --- /dev/null +++ b/test/typeparam/issue47892b.dir/a.go @@ -0,0 +1,29 @@ +// 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 + +type T struct{ p *int64 } + +type i struct{} + +func G() *T { return &T{nil} } + +func (j i) F(a, b *T) *T { + n := *a.p + *b.p + return &T{&n} +} + +func (j i) G() *T { + return &T{} +} + +type I[Idx any] interface { + G() Idx + F(a, b Idx) Idx +} + +func Gen() I[*T] { + return i{} +} diff --git a/test/typeparam/issue47892b.dir/main.go b/test/typeparam/issue47892b.dir/main.go new file mode 100644 index 0000000000..70df4408af --- /dev/null +++ b/test/typeparam/issue47892b.dir/main.go @@ -0,0 +1,17 @@ +// 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 main + +import "a" + +type S[Idx any] struct { + A string + B Idx +} + +type O[Idx any] struct { + A int + B a.I[Idx] +} diff --git a/test/typeparam/issue47892b.go b/test/typeparam/issue47892b.go new file mode 100644 index 0000000000..87b4ff46c1 --- /dev/null +++ b/test/typeparam/issue47892b.go @@ -0,0 +1,7 @@ +// compiledir -G=3 + +// 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 ignored -- 2.50.0