From 755d6de1d8cf9d7fff3a64eac30090cdfebe7c14 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 19 Oct 2020 21:49:57 -0700 Subject: [PATCH] [dev.typeparams] cmd/compile/internal/types2: add some more tests Change-Id: I36fce5462d11dd2e8fc9a619118c6a63eed4980a Reviewed-on: https://go-review.googlesource.com/c/go/+/263633 Trust: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- .../internal/types2/testdata/issue23203a.src | 14 ++++ .../internal/types2/testdata/issue23203b.src | 14 ++++ .../internal/types2/testdata/issue26390.src | 11 +++ .../internal/types2/testdata/issue28251.src | 65 +++++++++++++++ .../internal/types2/testdata/issue6977.src | 82 +++++++++++++++++++ 5 files changed, 186 insertions(+) create mode 100644 src/cmd/compile/internal/types2/testdata/issue23203a.src create mode 100644 src/cmd/compile/internal/types2/testdata/issue23203b.src create mode 100644 src/cmd/compile/internal/types2/testdata/issue26390.src create mode 100644 src/cmd/compile/internal/types2/testdata/issue28251.src create mode 100644 src/cmd/compile/internal/types2/testdata/issue6977.src diff --git a/src/cmd/compile/internal/types2/testdata/issue23203a.src b/src/cmd/compile/internal/types2/testdata/issue23203a.src new file mode 100644 index 0000000000..48cb5889cd --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/issue23203a.src @@ -0,0 +1,14 @@ +// Copyright 2018 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 "unsafe" + +type T struct{} + +func (T) m1() {} +func (T) m2([unsafe.Sizeof(T.m1)]int) {} + +func main() {} diff --git a/src/cmd/compile/internal/types2/testdata/issue23203b.src b/src/cmd/compile/internal/types2/testdata/issue23203b.src new file mode 100644 index 0000000000..638ec6c5ce --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/issue23203b.src @@ -0,0 +1,14 @@ +// Copyright 2018 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 "unsafe" + +type T struct{} + +func (T) m2([unsafe.Sizeof(T.m1)]int) {} +func (T) m1() {} + +func main() {} diff --git a/src/cmd/compile/internal/types2/testdata/issue26390.src b/src/cmd/compile/internal/types2/testdata/issue26390.src new file mode 100644 index 0000000000..b8e67e9bdd --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/issue26390.src @@ -0,0 +1,11 @@ +// Copyright 2018 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 issue26390 + +type A = T + +func (t *T) m() *A { return t } + +type T struct{} diff --git a/src/cmd/compile/internal/types2/testdata/issue28251.src b/src/cmd/compile/internal/types2/testdata/issue28251.src new file mode 100644 index 0000000000..cd79e0e8b5 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/issue28251.src @@ -0,0 +1,65 @@ +// Copyright 2018 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 test cases for various forms of +// method receiver declarations, per the spec clarification +// https://golang.org/cl/142757. + +package issue28251 + +// test case from issue28251 +type T struct{} + +type T0 = *T + +func (T0) m() {} + +func _() { (&T{}).m() } + +// various alternative forms +type ( + T1 = (((T))) +) + +func ((*(T1))) m1() {} +func _() { (T{}).m2() } +func _() { (&T{}).m2() } + +type ( + T2 = (((T3))) + T3 = T +) + +func (T2) m2() {} +func _() { (T{}).m2() } +func _() { (&T{}).m2() } + +type ( + T4 = ((*(T5))) + T5 = T +) + +func (T4) m4() {} +func _() { (T{}).m4 /* ERROR "cannot call pointer method m4 on T" */ () } +func _() { (&T{}).m4() } + +type ( + T6 = (((T7))) + T7 = (*(T8)) + T8 = T +) + +func (T6) m6() {} +func _() { (T{}).m6 /* ERROR "cannot call pointer method m6 on T" */ () } +func _() { (&T{}).m6() } + +type ( + T9 = *T10 + T10 = *T11 + T11 = T +) + +func (T9 /* ERROR invalid receiver \*\*T */ ) m9() {} +func _() { (T{}).m9 /* ERROR has no field or method m9 */ () } +func _() { (&T{}).m9 /* ERROR has no field or method m9 */ () } diff --git a/src/cmd/compile/internal/types2/testdata/issue6977.src b/src/cmd/compile/internal/types2/testdata/issue6977.src new file mode 100644 index 0000000000..8f4e9ba2b2 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/issue6977.src @@ -0,0 +1,82 @@ +// Copyright 2019 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 p + +import "io" + +// Alan's initial report. + +type I interface { f(); String() string } +type J interface { g(); String() string } + +type IJ1 = interface { I; J } +type IJ2 = interface { f(); g(); String() string } + +var _ = (*IJ1)(nil) == (*IJ2)(nil) // static assert that IJ1 and IJ2 are identical types + +// The canonical example. + +type ReadWriteCloser interface { io.ReadCloser; io.WriteCloser } + +// Some more cases. + +type M interface { m() } +type M32 interface { m() int32 } +type M64 interface { m() int64 } + +type U1 interface { m() } +type U2 interface { m(); M } +type U3 interface { M; m() } +type U4 interface { M; M; M } +type U5 interface { U1; U2; U3; U4 } + +type U6 interface { m(); m /* ERROR duplicate method */ () } +type U7 interface { M32 /* ERROR duplicate method */ ; m() } +type U8 interface { m(); M32 /* ERROR duplicate method */ } +type U9 interface { M32; M64 /* ERROR duplicate method */ } + +// Verify that repeated embedding of the same interface(s) +// eliminates duplicate methods early (rather than at the +// end) to prevent exponential memory and time use. +// Without early elimination, computing T29 may take dozens +// of minutes. +type ( + T0 interface { m() } + T1 interface { T0; T0 } + T2 interface { T1; T1 } + T3 interface { T2; T2 } + T4 interface { T3; T3 } + T5 interface { T4; T4 } + T6 interface { T5; T5 } + T7 interface { T6; T6 } + T8 interface { T7; T7 } + T9 interface { T8; T8 } + + T10 interface { T9; T9 } + T11 interface { T10; T10 } + T12 interface { T11; T11 } + T13 interface { T12; T12 } + T14 interface { T13; T13 } + T15 interface { T14; T14 } + T16 interface { T15; T15 } + T17 interface { T16; T16 } + T18 interface { T17; T17 } + T19 interface { T18; T18 } + + T20 interface { T19; T19 } + T21 interface { T20; T20 } + T22 interface { T21; T21 } + T23 interface { T22; T22 } + T24 interface { T23; T23 } + T25 interface { T24; T24 } + T26 interface { T25; T25 } + T27 interface { T26; T26 } + T28 interface { T27; T27 } + T29 interface { T28; T28 } +) + +// Verify that m is present. +var x T29 +var _ = x.m -- 2.50.0