mirror of
https://github.com/golang/go
synced 2024-11-23 19:40:08 -07:00
These two tests fail with the 1.18 compiler frontend, because of incomplete dictionary support. This CL adds the tests for Unified IR, which currently handles them correctly, to make sure it doesn't repeat the same errors. Updates #53276. Updates #53328. Change-Id: I9f436495d28f2bc5707a17bd2527c86abacf91f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/411695 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
8ef8b60e18
commit
f73ad3d24d
@ -1966,6 +1966,8 @@ var types2Failures32Bit = setOf(
|
||||
var go118Failures = setOf(
|
||||
"typeparam/nested.go", // 1.18 compiler doesn't support function-local types with generics
|
||||
"typeparam/issue51521.go", // 1.18 compiler produces bad panic message and link error
|
||||
"typeparam/mdempsky/16.go", // 1.18 compiler uses interface shape type in failed type assertions
|
||||
"typeparam/mdempsky/17.go", // 1.18 compiler mishandles implicit conversions from range loops
|
||||
)
|
||||
|
||||
// In all of these cases, the 1.17 compiler reports reasonable errors, but either the
|
||||
|
34
test/typeparam/mdempsky/16.go
Normal file
34
test/typeparam/mdempsky/16.go
Normal file
@ -0,0 +1,34 @@
|
||||
// run
|
||||
|
||||
// Copyright 2022 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.
|
||||
|
||||
// Test that type assertion panics mention the real interface type,
|
||||
// not their shape type.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// The exact error message isn't important, but it should mention
|
||||
// `main.T`, not `go.shape.int_0`.
|
||||
if have := F[T](); !strings.Contains(have, "interface { T() main.T }") {
|
||||
fmt.Printf("FAIL: unexpected panic message: %q\n", have)
|
||||
}
|
||||
}
|
||||
|
||||
type T int
|
||||
|
||||
func F[T any]() (res string) {
|
||||
defer func() {
|
||||
res = recover().(runtime.Error).Error()
|
||||
}()
|
||||
_ = interface{ T() T }(nil).(T)
|
||||
return
|
||||
}
|
110
test/typeparam/mdempsky/17.go
Normal file
110
test/typeparam/mdempsky/17.go
Normal file
@ -0,0 +1,110 @@
|
||||
// run
|
||||
|
||||
// Copyright 2022 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.
|
||||
|
||||
// Test that implicit conversions of derived types to interface type
|
||||
// in range loops work correctly.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func main() {
|
||||
test{"int", "V"}.match(RangeArrayAny[V]())
|
||||
test{"int", "V"}.match(RangeArrayIface[V]())
|
||||
test{"V"}.match(RangeChanAny[V]())
|
||||
test{"V"}.match(RangeChanIface[V]())
|
||||
test{"K", "V"}.match(RangeMapAny[K, V]())
|
||||
test{"K", "V"}.match(RangeMapIface[K, V]())
|
||||
test{"int", "V"}.match(RangeSliceAny[V]())
|
||||
test{"int", "V"}.match(RangeSliceIface[V]())
|
||||
}
|
||||
|
||||
type test []string
|
||||
|
||||
func (t test) match(args ...any) {
|
||||
if len(t) != len(args) {
|
||||
fmt.Printf("FAIL: want %v values, have %v\n", len(t), len(args))
|
||||
return
|
||||
}
|
||||
for i, want := range t {
|
||||
if have := reflect.TypeOf(args[i]).Name(); want != have {
|
||||
fmt.Printf("FAIL: %v: want type %v, have %v\n", i, want, have)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type iface interface{ M() int }
|
||||
|
||||
type K int
|
||||
type V int
|
||||
|
||||
func (K) M() int { return 0 }
|
||||
func (V) M() int { return 0 }
|
||||
|
||||
func RangeArrayAny[V any]() (k, v any) {
|
||||
for k, v = range [...]V{zero[V]()} {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RangeArrayIface[V iface]() (k any, v iface) {
|
||||
for k, v = range [...]V{zero[V]()} {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RangeChanAny[V any]() (v any) {
|
||||
for v = range chanOf(zero[V]()) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RangeChanIface[V iface]() (v iface) {
|
||||
for v = range chanOf(zero[V]()) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RangeMapAny[K comparable, V any]() (k, v any) {
|
||||
for k, v = range map[K]V{zero[K](): zero[V]()} {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RangeMapIface[K interface {
|
||||
iface
|
||||
comparable
|
||||
}, V iface]() (k, v iface) {
|
||||
for k, v = range map[K]V{zero[K](): zero[V]()} {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RangeSliceAny[V any]() (k, v any) {
|
||||
for k, v = range []V{zero[V]()} {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RangeSliceIface[V iface]() (k any, v iface) {
|
||||
for k, v = range []V{zero[V]()} {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func chanOf[T any](elems ...T) chan T {
|
||||
c := make(chan T, len(elems))
|
||||
for _, elem := range elems {
|
||||
c <- elem
|
||||
}
|
||||
close(c)
|
||||
return c
|
||||
}
|
||||
|
||||
func zero[T any]() (_ T) { return }
|
Loading…
Reference in New Issue
Block a user