Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
issue48424.go55 linesDownload Raw Back to typeparam
1// run2 3// Copyright 2021 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// Smoke test for constraint literals with elided interface8// per issue #48424.9 10package main11 12func identity[T int](x T) T {13	return x14}15 16func min[T int | string](x, y T) T {17	if x < y {18		return x19	}20	return y21}22 23func max[T ~int | ~float64](x, y T) T {24	if x > y {25		return x26	}27	return y28}29 30func main() {31	if identity(1) != 1 {32		panic("identity(1) failed")33	}34 35	if min(2, 3) != 2 {36		panic("min(2, 3) failed")37	}38 39	if min("foo", "bar") != "bar" {40		panic(`min("foo", "bar") failed`)41	}42 43	if max(2, 3) != 3 {44		panic("max(2, 3) failed")45	}46}47 48// Some random type parameter lists with elided interfaces.49 50type (51	_[T struct{}]                     struct{}52	_[M map[K]V, K comparable, V any] struct{}53	_[_ interface{} | int]            struct{}54)55 
codekingpro/portable-devtools · Team Ai