Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
builtins.go113 linesDownload Raw Back to typeparam
1// compile2 3// Copyright 2020 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 7// This file tests built-in calls on generic types.8 9// derived and expanded from cmd/compile/internal/types2/testdata/check/builtins.go210 11package builtins12 13// close14 15type C0 interface{ int }16type C1 interface{ chan int }17type C2 interface{ chan int | <-chan int }18type C3 interface{ chan int | chan float32 }19type C4 interface{ chan int | chan<- int }20type C5[T any] interface{ ~chan T | chan<- T }21 22func f1[T C1](ch T) {23	close(ch)24}25 26func f2[T C3](ch T) {27	close(ch)28}29 30func f3[T C4](ch T) {31	close(ch)32}33 34func f4[T C5[X], X any](ch T) {35	close(ch)36}37 38// delete39 40type M0 interface{ int }41type M1 interface{ map[string]int }42type M2 interface {43	map[string]int | map[string]float6444}45type M3 interface{ map[string]int | map[rune]int }46type M4[K comparable, V any] interface{ map[K]V | map[rune]V }47 48func g1[T M1](m T) {49	delete(m, "foo")50}51 52func g2[T M2](m T) {53	delete(m, "foo")54}55 56func g3[T M4[rune, V], V any](m T) {57	delete(m, 'k')58}59 60// make61 62func m1[63	S1 interface{ []int },64	S2 interface{ []int | chan int },65 66	M1 interface{ map[string]int },67	M2 interface{ map[string]int | chan int },68 69	C1 interface{ chan int },70	C2 interface{ chan int | chan string },71]() {72	type m1S0 []int73	type m1M0 map[string]int74	type m1C0 chan int75 76	_ = make([]int, 10)77	_ = make(m1S0, 10)78	_ = make(S1, 10)79	_ = make(S1, 10, 20)80 81	_ = make(map[string]int)82	_ = make(m1M0)83	_ = make(M1)84	_ = make(M1, 10)85 86	_ = make(chan int)87	_ = make(m1C0)88	_ = make(C1)89	_ = make(C1, 10)90}91 92// len/cap93 94type Slice[T any] interface {95	[]T96}97 98func c1[T any, S Slice[T]]() {99	x := make(S, 5, 10)100	_ = len(x)101	_ = cap(x)102}103 104// append105 106func a1[T any, S Slice[T]]() {107	x := make(S, 5)108	y := make(S, 2)109	var z T110	_ = append(x, y...)111	_ = append(x, z)112}113 
codekingpro/portable-devtools · Team Ai