code
stringlengths
10
1.34M
language
stringclasses
1 value
// errorcheck // Copyright 2011 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. // Verify that erroneous type switches are caught be the compiler. // Issue 2700, among other things. // Does not compile. package main import ...
Go
// run // Copyright 2009 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. // Test stack splitting code. // Try to tickle stack splitting bugs by doing // go, defer, and closure calls at different stack depths. package main t...
Go
// run // Copyright 2009 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. // Test maps, almost exhaustively. package main import ( "fmt" "math" "strconv" "time" ) const count = 100 func P(a []string) string { s := "{"...
Go
// run // Copyright 2009 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. // Test correct short declarations and redeclarations. package main func f1() int { return 1 } func f2() (float32, int) { r...
Go
// errorcheck // Copyright 2010 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 main fmt.Printf("hello") // ERROR "non-declaration statement outside function body|expected declaration" func main() { } x++ // ERROR...
Go
// errorcheck // Copyright 2010 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 main func main() { // ERROR "unexpected semicolon or newline before .?{.?"
Go
// errorcheck // Copyright 2010 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 main import ( "io", // ERROR "unexpected comma" "os" )
Go
// errorcheck // Copyright 2012 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 main var a = []int{ 3 // ERROR "need trailing comma before newline in composite literal" }
Go
// errorcheck // Copyright 2011 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 main func main() { switch main() := interface{}(nil).(type) { // ERROR "invalid variable name" default: } }
Go
// errorcheck // Copyright 2010 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 main func main() { if x; y // ERROR "unexpected semicolon or newline before .?{.?|undefined" { z // GCCGO_ERROR "undefined"
Go
// errorcheck // Copyright 2010 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 main type xyz struct { ch chan } // ERROR "unexpected .*}.* in channel type" func Foo(y chan) { // ERROR "unexpected .*\).* in cha...
Go
// errorcheck // Copyright 2010 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 main type T interface { f, g () // ERROR "name list not allowed in interface type" }
Go
// errorcheck // Copyright 2010 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 main func main() { for x; y; z // ERROR "unexpected semicolon or newline before .?{.?|undefined" { z // GCCGO_ERROR "undefined"
Go
// errorcheck // Copyright 2010 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 main func main() { if x { } // GCCGO_ERROR "undefined" else { } // ERROR "unexpected semicolon or newline before .?else.?" }
Go
// errorcheck // Copyright 2010 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 main var c chan int var v int func main() { if c <- v { // ERROR "send statement.*value.*select" } } var _ = c <- v // ERROR "send ...
Go
// errorcheck // Copyright 2010 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 main func main() { var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement|expected ';' or '}' or newline"
Go
// errorcheck // Copyright 2010 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 main func main() { for x // GCCGO_ERROR "undefined" { // ERROR "unexpected semicolon or newline before .?{.?" z // GCCGO_ERROR "u...
Go
// errorcheck // Copyright 2011 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 main func main() { if true { } else ; // ERROR "else must be followed by if or statement block|expected .if. or .{." }
Go
// errorcheck // Copyright 2010 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 main var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement|expected ';' or newline after top level declaration" ...
Go
// errorcheck // Copyright 2010 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 main func main() { for var x = 0; x < 10; x++ { // ERROR "var declaration not allowed in for initializer"
Go
// errorcheck // Copyright 2010 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 main type T // ERROR "unexpected semicolon or newline in type declaration" {
Go
// errorcheck // Copyright 2010 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 main func main() { switch x; y // ERROR "unexpected semicolon or newline before .?{.?|undefined" { z
Go
// errorcheck // Copyright 2011 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 main func x() { } func main() { if { // ERROR "missing condition" } if x(); { // ERROR "missing condition" } }
Go
// compile // Copyright 2009 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. // Test function signatures. // Compiled but not run. package main type t1 int type t2 int type t3 int func f1(t1, t2, t3) func f2(t1, t2, t3 boo...
Go
// errorcheck // Copyright 2009 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. // Test that even if a file imports runtime, // it cannot get at the low-level runtime definitions // known to the compiler. For normal package...
Go
// $G $D/$F.go && $L -X main.tbd hello $F.$A && ./$A.out // Copyright 2012 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. // Test the -X facility of the gc linker (6l etc.). package main var tbd string func main() { if ...
Go
// run // Copyright 2010 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. // Semi-exhaustive test for the append predeclared function. package main import ( "fmt" "reflect" ) func verify(name string, result, expected int...
Go
// errorcheck // Copyright 2011 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. // Verify that erroneous labels are caught by the compiler. // This set is caught by pass 2. That's why this file is label1.go. // Does not com...
Go
// run // Copyright 2011 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. // Test len constants and non-constants, http://golang.org/issue/3244. package main var b struct { a[10]int } var m map[string][20]int var s [][30]...
Go
// run // Copyright 2009 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. // Test that basic operations on named types are valid // and preserve the type. package main type Array [10]byte type Bool bool type Chan chan int t...
Go
// errorcheck // Copyright 2009 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. // Verify that illegal function signatures are detected. // Does not compile. package main type t1 int type t2 int type t3 int func f1(*t2, x ...
Go
// build // Copyright 2009 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. // Test basic concurrency: the classic prime sieve. // Do not run - loops forever. package main // Send the sequence 2, 3, 4, ... to channel 'ch'. f...
Go
// run // Copyright 2009 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. // Test character literal syntax. package main import "os" func main() { var i uint64 = ' ' + 'a' + 'ä' + '本' + '\a' + '\b' + '\f' + ...
Go
// run // Copyright 2009 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. // Test types of constant expressions, using reflect. package main import "reflect" func typeof(x interface{}) string { return reflect.TypeOf(x).Stri...
Go
// $G $D/$F.go $D/z*.go && $L $F.$A && ./$A.out // Copyright 2009 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 main func main() { F1() F2() F3() F4() F5() F6() F7() F8() F9() F10() F11() F12() F13() F14() F15() F16...
Go
//line x6.go:4 package main func F6() {}
Go
//line x17.go:4 package main func F17() {}
Go
//line x10.go:4 package main func F10() {}
Go
//line x2.go:4 package main func F2() {}
Go
//line x12.go:4 package main func F12() {}
Go
//line x4.go:4 package main func F4() {}
Go
//line x9.go:4 package main func F9() {}
Go
//line x11.go:4 package main func F11() {}
Go
//line x14.go:4 package main func F14() {}
Go
//line x16.go:4 package main func F16() {}
Go
//line x13.go:4 package main func F13() {}
Go
//line x18.go:4 package main func F18() {}
Go
//line x7.go:4 package main func F7() {}
Go
//line x19.go:4 package main func F19() {}
Go
//line x5.go:4 package main func F5() {}
Go
// run // Copyright 2011 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. //line foo/bar.y:4 package main //line foo/bar.y:60 func main() { //line foo/bar.y:297 f, l := 0, 0 //line yacctab:1 f, l = 1, 1 //line yaccpar:1 f,...
Go
//line x15.go:4 package main func F15() {}
Go
//line x8.go:4 package main func F8() {}
Go
//line x1.go:4 package main func F1() {}
Go
//line x3.go:4 package main func F3() {}
Go
//line x20.go:4 package main func F20() {}
Go
// run // Copyright 2011 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. // Test reordering of assignments. package main import "fmt" func main() { p1() p2() p3() p4() p5() p6() p7() p8() } var gx []int func f(i...
Go
// run // Copyright 2009 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 main // Test for correct heap-moving of escaped variables. // It is hard to check for the allocations, but it is easy // to check that if you c...
Go
// echo bug395 is broken # takes 90+ seconds to break // # $G $D/$F.go || echo bug395 // Copyright 2011 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. // Issue 1909 // Would OOM due to exponential recursion on Foo's expand...
Go
// run // Copyright 2009 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. // Test simple methods of various types, with pointer and // value receivers. package main type S string type S1 string type I int type I1 int type T ...
Go
// errorcheck // Copyright 2010 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. // Verify that a couple of illegal variable declarations are caught by the compiler. // Does not compile. package main func main() { _ = asdf...
Go
// run // Copyright 2009 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. // Test UTF-8 in strings and character constants. package main import "unicode/utf8" func main() { var chars [6]rune chars[0] = 'a' chars[1] = 'b'...
Go
// errorcheck // Copyright 2009 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. // Verify that method redeclarations are caught by the compiler. // Does not compile. package main type T struct { } func (t *T) M(int, string)...
Go
// run // Copyright 2009 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. // Test for loops. package main func assertequal(is, shouldbe int, msg string) { if is != shouldbe { print("assertion fail", msg, "\n") panic(1) ...
Go
// $G $D/$F.go && $L $F.$A && // ./$A.out -pass 0 >tmp.go && $G tmp.go && $L -o $A.out1 tmp.$A && ./$A.out1 && // ./$A.out -pass 1 >tmp.go && errchk $G -e tmp.go && // ./$A.out -pass 2 >tmp.go && errchk $G -e tmp.go // rm -f tmp.go $A.out1 // Copyright 2010 The Go Authors. All rights reserved. // Use of this source c...
Go
// run // Copyright 2009 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. // Test functions and goroutines. package main func caller(f func(int, int) int, a, b int, c chan int) { c <- f(a, b) } func gocall(f func(int, int)...
Go
// run // Copyright 2009 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. // Test iota. package main func assert(cond bool, msg string) { if !cond { print("assertion fail: ", msg, "\n") panic(1) } } const ( x int = i...
Go
// run // Copyright 2009 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. // Test simulating a Turing machine, sort of. package main // brainfuck var p, pc int var a [30000]byte const prog = "++++++++++[>+++++++>++++++++++...
Go
// errorcheck // Copyright 2009 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. // Verify that illegal uses of composite literals are detected. // Does not compile. package main var a = []int { "a" }; // ERROR "conver|incom...
Go
// run // Copyright 2009 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. // Test behavior of the blank identifier (_). package main import _ "fmt" var call string type T struct { _, _, _ int } func (T) _() { } func (T)...
Go
// run // Copyright 2009 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. // Test the cap predeclared function applied to channels. package main func main() { c := make(chan int, 10) if len(c) != 0 || cap(c) != 10 { prin...
Go
// $G -S $D/$F.go | egrep initdone >/dev/null && echo BUG sinit || true // Copyright 2010 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. // Test that many initializations can be done at link time and // generate no executab...
Go
// errorcheck // Copyright 2009 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. // Verify that renamed identifiers no longer have their old meaning. // Does not compile. package main func main() { var n byte // ERRO...
Go
// run // Copyright 2009 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. // Test for loops of many forms. package main func assertequal(is, shouldbe int, msg string) { if is != shouldbe { print("assertion fail" + msg + "...
Go
// run // Copyright 2009 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. // Test scoping of variables. package main var x,y int; func main() { x = 15; y = 20; { var x int; x = 25; y = 25; _ = x; } x = x+y; ...
Go
// run // Copyright 2010 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. // Test composition, decomposition, and reflection on complex numbers. package main import "unsafe" import "reflect" const ( R = 5 I = 6i C1 = R ...
Go
// run // Copyright 2009 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. // Test basic operations of slices and arrays. package main var bx [10]byte var by []byte var fx [10]float64 var fy []float64 var lb, hb int var t int...
Go
// run // Copyright 2010 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. // Test simple arithmetic and assignment for complex numbers. package main const ( R = 5 I = 6i C1 = R + I // ADD(5,6) ) func main() { var b boo...
Go
// run // Copyright 2009 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. // Test simple functions. package main func main() { var x int; x = fun(10,20,30); if x != 60 { panic(x); } } func fun(ia,ib,ic int)int { var o ...
Go
// run // Copyright 2009 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. // Test simple multi-argument multi-valued function. package main func main() { var x,y int; x,y = simple(10,20,30); if x+y != 65 { panic(x+y); } ...
Go
// run // Copyright 2009 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. // Test interface assignment. package main type Iputs interface { puts (s string) string; } // --------- type Print struct { whoami int; put Iput...
Go
// run // Copyright 2009 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. // Test method invocation with pointer receivers and function-valued fields. package main type C struct { a int; x func(p *C)int; } func (this *C) ...
Go
// run // Copyright 2009 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. // Test communication operations including select. package main import "os" import "runtime" import "sync" var randx int func nrand(n int) int { ra...
Go
// run // Copyright 2010 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. // Test complex numbers,including fmt support. // Used to crash. package main import "fmt" const ( R = 5 I = 6i C1 = R + I // ADD(5,6) ) func wa...
Go
// run // Copyright 2009 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. // Test integer modulus by contstants. package main import "math/rand" const Count = 1e5 func i64rand() int64 { for { a := int64(rand.Uint32()) ...
Go
// run // Copyright 2009 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. // Test basic operations on bool. package main type s struct { a bool; b bool; } func main() { var a,b bool; a = true; b = false; if !a { pan...
Go
// run // Copyright 2009 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. // Test pointers and the . (selector) operator on structs. package main type x2 struct { a,b,c int; d int; }; var g1 x2; var g2 struct { a,b,c int; d ...
Go
// run // Copyright 2009 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. // Test integer division and modulus. package main const ( // example from the spec n1 = +5 n2 = -5 d1 = +3 d2 = -3 q1 = +1 q2 = -1 q3 = -1 ...
Go
// run // Copyright 2009 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. // Test simple arithmetic conversion. package main type vlong int64 type short int16 func main() { s1 := vlong(0) for i := short(0); i < 10; i = i ...
Go
// run // Copyright 2009 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. // Test interfaces and methods. package main type S struct { a,b int; } type I1 interface { f ()int; } type I2 interface { g() int; f() int; } ...
Go
// run // Copyright 2010 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. // Test compound types made of complex numbers. package main var a [12]complex128 var s []complex128 var c chan complex128 var f struct { c complex12...
Go
// run // Copyright 2009 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. // Test slicing and re-slicing. package main var bx []byte var by []byte var fx []float64 var fy []float64 var lb, hb int var t int func main() { /...
Go
// run // Copyright 2009 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. // Test simple function literals. package main func main() { x := func(a int)int { x := func(a int)int { x := func(a int)int { return a+5; ...
Go
// run // Copyright 2009 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. // Test general operation using s-list. // First Go program ever run (although not in this exact form). package main import "fmt" const nilchar = 0 ...
Go
// run // Copyright 2009 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. // Test communication with multiple simultaneous goroutines. package main import "runtime" const N = 1000 // sent messages const M = 10 // receivin...
Go
// run // Copyright 2009 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. // Test general operation using a list implementation. package main type Item interface { Print() string } type ListItem struct { item Item next *...
Go
// run // Copyright 2010 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. // Test, near-exhaustive, of converting numbers between types. // No complex numbers though. package main var i8 int8; var u8 uint8; var i16 int16; va...
Go
// run // Copyright 2009 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. // Test interfaces on basic types. package main type myint int type mystring string type I0 interface{} func f() { var ia, ib I0 var i myint var s...
Go
// cmpout // Copyright 2010 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. // Test trivial, bootstrap-level complex numbers, including printing. package main const ( R = 5 I = 6i C1 = R + I // ADD(5,6) ) func doprint(...
Go
// run // Copyright 2009 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. // Test integer division by constants. package main import "math/rand" const Count = 1e5 func i64rand() int64 { for { a := int64(rand.Uint32()) ...
Go