Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
indirect.go88 linesDownload Raw Back to test
1// run2 3// Copyright 2009 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// Test various safe uses of indirection.8 9package main10 11var m0 map[string]int12var m1 *map[string]int13var m2 *map[string]int = &m014var m3 map[string]int = map[string]int{"a": 1}15var m4 *map[string]int = &m316 17var s0 string18var s1 *string19var s2 *string = &s020var s3 string = "a"21var s4 *string = &s322 23var a0 [10]int24var a1 *[10]int25var a2 *[10]int = &a026 27var b0 []int28var b1 *[]int29var b2 *[]int = &b030var b3 []int = []int{1, 2, 3}31var b4 *[]int = &b332 33func crash() {34	// these uses of nil pointers35	// would crash but should type check36	println("crash",37		len(a1)+cap(a1))38}39 40func nocrash() {41	// this is spaced funny so that42	// the compiler will print a different43	// line number for each len call if44	// it decides there are type errors.45	// it might also help in the traceback.46	x :=47		len(m0) +48			len(m3)49	if x != 1 {50		println("wrong maplen")51		panic("fail")52	}53 54	x =55		len(s0) +56			len(s3)57	if x != 1 {58		println("wrong stringlen")59		panic("fail")60	}61 62	x =63		len(a0) +64			len(a2)65	if x != 20 {66		println("wrong arraylen")67		panic("fail")68	}69 70	x =71		len(b0) +72			len(b3)73	if x != 3 {74		println("wrong slicelen")75		panic("fail")76	}77 78	x =79		cap(b0) +80			cap(b3)81	if x != 3 {82		println("wrong slicecap")83		panic("fail")84	}85}86 87func main() { nocrash() }88 
codekingpro/portable-devtools · Team Ai