go issue50782 源码

  • 2022-07-15
  • 浏览 (509)

golang issue50782 代码

文件路径:/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50782.go

// 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.

// Field accesses through type parameters are disabled
// until we have a more thorough understanding of the
// implications on the spec. See issue #51576.

package p

// The first example from the issue.
type Numeric interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

// numericAbs matches numeric types with an Abs method.
type numericAbs[T Numeric] interface {
	~struct{ Value T }
	Abs() T
}

// AbsDifference computes the absolute value of the difference of
// a and b, where the absolute value is determined by the Abs method.
func absDifference[T numericAbs[T /* ERROR T does not implement Numeric */]](a, b T) T {
	// Field accesses are not permitted for now. Keep an error so
	// we can find and fix this code once the situation changes.
	return a.Value // ERROR a\.Value undefined
	// TODO: The error below should probably be positioned on the '-'.
	// d := a /* ERROR "invalid operation: operator - not defined" */ .Value - b.Value
	// return d.Abs()
}

// The second example from the issue.
type T[P int] struct{ f P }

func _[P T[P /* ERROR "P does not implement int" */ ]]() {}

// Additional tests
func _[P T[T /* ERROR "T\[P\] does not implement int" */ [P /* ERROR "P does not implement int" */ ]]]() {}
func _[P T[Q /* ERROR "Q does not implement int" */ ], Q T[P /* ERROR "P does not implement int" */ ]]() {}
func _[P T[Q], Q int]() {}

type C[P comparable] struct{ f P }
func _[P C[C[P]]]() {}
func _[P C[C /* ERROR "C\[Q\] does not implement comparable" */ [Q /* ERROR "Q does not implement comparable" */]], Q func()]() {}
func _[P [10]C[P]]() {}
func _[P struct{ f C[C[P]]}]() {}

相关信息

go 源码目录

相关文章

go issue20583 源码

go issue23203a 源码

go issue23203b 源码

go issue25838 源码

go issue26390 源码

go issue28251 源码

go issue39634 源码

go issue39664 源码

go issue39680 源码

go issue39693 源码