Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
issue50417b.go59 linesDownload Raw Back to typeparam
1// run2 3// Copyright 2022 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7package main8 9func main() {}10 11// Field accesses through type parameters are disabled12// until we have a more thorough understanding of the13// implications on the spec. See issue #51576.14 15/*16import "fmt"17 18type MyStruct struct {19	b1, b2 string20	E21}22 23type E struct {24	val int25}26 27type C interface {28	~struct {29		b1, b2 string30		E31	}32}33 34func f[T C]() T {35	var x T = T{36		b1: "a",37		b2: "b",38	}39 40	if got, want := x.b2, "b"; got != want {41		panic(fmt.Sprintf("got %d, want %d", got, want))42	}43	x.b1 = "y"44	x.val = 545 46	return x47}48 49func main() {50	x := f[MyStruct]()51	if got, want := x.b1, "y"; got != want {52		panic(fmt.Sprintf("got %d, want %d", got, want))53	}54	if got, want := x.val, 5; got != want {55		panic(fmt.Sprintf("got %d, want %d", got, want))56	}57}58*/59 
codekingpro/portable-devtools · Team Ai