From 7de2249a08aab44c512d0ea86f50481d76e135f1 Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Tue, 28 Dec 2021 18:40:12 -0800 Subject: cmd/compile, test: updated comments in crawler.go, added test Added a test to make sure that the private methods of a local generic type are properly exported, if there is a global variable with that type. Added comments in crawler.go, to give more detail and to give more about the overall purpose. Fixed one place where t.isFullyInstantiated() should be replaced by isPtrFullyInstantiated(t), so that we catch pointers to generic types that may be used as a method receiver. Change-Id: I9c42d14eb6ebe14d249df7c8fa39e889f7cd3f22 Reviewed-on: https://go-review.googlesource.com/c/go/+/374754 Reviewed-by: Matthew Dempsky Trust: Dan Scales Run-TryBot: Dan Scales TryBot-Result: Gopher Robot --- test/typeparam/gencrawler.dir/a.go | 27 +++++++++++++++++++++++++++ test/typeparam/gencrawler.dir/main.go | 12 ++++++++++++ test/typeparam/gencrawler.go | 10 ++++++++++ test/typeparam/gencrawler.out | 2 ++ 4 files changed, 51 insertions(+) create mode 100644 test/typeparam/gencrawler.dir/a.go create mode 100644 test/typeparam/gencrawler.dir/main.go create mode 100644 test/typeparam/gencrawler.go create mode 100644 test/typeparam/gencrawler.out (limited to 'test/typeparam') diff --git a/test/typeparam/gencrawler.dir/a.go b/test/typeparam/gencrawler.dir/a.go new file mode 100644 index 0000000000..50d6b4adeb --- /dev/null +++ b/test/typeparam/gencrawler.dir/a.go @@ -0,0 +1,27 @@ +// 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 + +var V val[int] + +type val[T any] struct { + valx T +} + +func (v *val[T]) Print() { + v.print1() +} + +func (v *val[T]) print1() { + println(v.valx) +} + +func (v *val[T]) fnprint1() { + println(v.valx) +} + +func FnPrint[T any](v *val[T]) { + v.fnprint1() +} diff --git a/test/typeparam/gencrawler.dir/main.go b/test/typeparam/gencrawler.dir/main.go new file mode 100644 index 0000000000..063de7f350 --- /dev/null +++ b/test/typeparam/gencrawler.dir/main.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 main + +import "a" + +func main() { + a.V.Print() + a.FnPrint(&a.V) +} diff --git a/test/typeparam/gencrawler.go b/test/typeparam/gencrawler.go new file mode 100644 index 0000000000..7c268aed51 --- /dev/null +++ b/test/typeparam/gencrawler.go @@ -0,0 +1,10 @@ +// 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. + +// Testing that all methods of a private generic type are exported, if a variable +// with that type is exported. + +package ignored diff --git a/test/typeparam/gencrawler.out b/test/typeparam/gencrawler.out new file mode 100644 index 0000000000..aa47d0d46d --- /dev/null +++ b/test/typeparam/gencrawler.out @@ -0,0 +1,2 @@ +0 +0 -- cgit v1.3-5-g9baa