mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[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 <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
1d07306a44
commit
755d6de1d8
5 changed files with 186 additions and 0 deletions
14
src/cmd/compile/internal/types2/testdata/issue23203a.src
vendored
Normal file
14
src/cmd/compile/internal/types2/testdata/issue23203a.src
vendored
Normal file
|
|
@ -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() {}
|
||||
14
src/cmd/compile/internal/types2/testdata/issue23203b.src
vendored
Normal file
14
src/cmd/compile/internal/types2/testdata/issue23203b.src
vendored
Normal file
|
|
@ -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() {}
|
||||
11
src/cmd/compile/internal/types2/testdata/issue26390.src
vendored
Normal file
11
src/cmd/compile/internal/types2/testdata/issue26390.src
vendored
Normal file
|
|
@ -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{}
|
||||
65
src/cmd/compile/internal/types2/testdata/issue28251.src
vendored
Normal file
65
src/cmd/compile/internal/types2/testdata/issue28251.src
vendored
Normal file
|
|
@ -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 */ () }
|
||||
82
src/cmd/compile/internal/types2/testdata/issue6977.src
vendored
Normal file
82
src/cmd/compile/internal/types2/testdata/issue6977.src
vendored
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue