go issue50426 源码

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

golang issue50426 代码

文件路径:/src/cmd/compile/internal/types2/testdata/fixedbugs/issue50426.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.

package p

type A1 [2]uint64
type A2 [2]uint64

func (a A1) m() A1 { return a }
func (a A2) m() A2 { return a }

func f[B any, T interface {
	A1 | A2
	m() T
}](v T) {
}

func _() {
	var v A2
	// Use function type inference to infer type A2 for T.
	// Don't use constraint type inference before function
	// type inference for typed arguments, otherwise it would
	// infer type [2]uint64 for T which doesn't have method m
	// (was the bug).
	f[int](v)
}

// Keep using constraint type inference before function type
// inference for untyped arguments so we infer type float64
// for E below, and not int (which would not work).
func g[S ~[]E, E any](S, E) {}

func _() {
	var s []float64
	g[[]float64](s, 0)
}

// Keep using constraint type inference after function
// type inference for untyped arguments so we infer
// missing type arguments for which we only have the
// untyped arguments as starting point.
func h[E any, R []E](v E) R { return R{v} }
func _() []int              { return h(0) }

相关信息

go 源码目录

相关文章

go issue20583 源码

go issue23203a 源码

go issue23203b 源码

go issue25838 源码

go issue26390 源码

go issue28251 源码

go issue39634 源码

go issue39664 源码

go issue39680 源码

go issue39693 源码

0  赞