code
stringlengths
10
1.34M
language
stringclasses
1 value
// 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 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 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 func main() { switch x; y // ERROR "unexpected semicolon or newline before .?{.?|undefined" { z
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 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 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 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 switch statements are detected by the compiler. // Does not compile. package main type I interface { M() } func bad(...
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 basic operations on named types are valid // and preserve the type. // Does not compile. package main type Bool bool type Map ma...
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
// 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 heavy recursion works. Simple torture test for // segmented stacks: do math in unary by recursion. package main type Number *Number // -...
Go
// [ "$GOOS" == windows ] || // ($G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.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. // Test that a program can survive SIGCHLD. 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 trailing commas. DO NOT gofmt THIS FILE. package main var a = []int{1, 2, } var b = [5]int{1, 2, 3, } var c = []int{1, } var d = [...]int{1, 2...
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. // Simple test of the garbage collector. package main import "runtime" func mk2() { b := new([10000]byte) _ = b // println(b, "stored at", &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 simple assignment errors are caught by the compiler. // Does not compile. package main import "sync" type T struct { int sync.Mute...
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 'for range' construct. package main // test range over channels func gen(c chan int, lo, hi int) { for i := lo; i <= hi; i++ { c <- 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 floating-point literal syntax. package main var bad bool func pow10(pow int) float64 { if pow < 0 { return 1 / pow10(-pow) } if pow > 0 ...
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
// 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 integer literal syntax. package main import "os" func main() { s := 0 + 123 + 0123 + 0000 + 0x0 + 0x123 + 0X0 + 0X123 if 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 initialization of package-level variables. package main import "fmt" import "reflect" type S struct { A, B, C, X, Y, Z int } type T struct ...
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 that top-level parenthesized declarations can be empty. // Compiles but does not run. package P import ( ) const ( ) var ( ) type ( )
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 that we can defer the predeclared functions print and println. package main func main() { defer println(42, true, false, true, 1.5, "worl...
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 zero length structs. // Used to not be evaluated. // Issue 2232. package main func recv(c chan interface{}) struct{} { return (<-c).(struct{...
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 character literals are detected. // Does not compile. package main const ( // check that surrogate pair elements are in...
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. // Test that error messages say what the source file says // (uint8 vs byte, int32 vs. rune). // Does not compile. package main import ( "fmt...
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 evaluation order in if condition. package main var calledf = false func f() int { calledf = true return 1 } func g() int { if !calledf {...
Go
// $G $F.go && $L $F.$A && ./$A.out arg1 arg2 // 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 os.Args. package main import "os" func main() { if len(os.Args) != 3 { panic("argc") } if os.Args...
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. // Test illegal shifts. // Issue 1708, illegal cases. // Does not compile. package p func f(x int) int { return 0 } func g(x interface...
Go
// [ "$GORUN" == "" ] || exit 0 # Android runner gets confused by the NUL output // $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go && // errchk $G -e tmp.go // rm -f tmp.go // 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 LI...
Go
/* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form ...
Go
// 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. // Garbage collection benchmark: parse Go packages repeatedly. package main import ( "flag" "fmt" "go/ast" "go/parser" "go/token" "log" "net/http" _ ...
Go
// 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 import ( "flag" "fmt" "log" "os" "runtime" "runtime/pprof" "time" "unsafe" ) const BranchingFactor = 4 type Object struct { child [Bra...
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 import ( "fmt" "runtime" "time" ) type Number struct { next *Number } // ------------------------------------- // Peano primitives ...
Go
// 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 ( "fmt" "runtime" "sort" "time" ) func gcstats(name string, n int, t time.Duration) { st := new(runtime.MemStats) runtime.ReadMemSt...
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 various safe uses of indirection. package main var m0 map[string]int var m1 *map[string]int var m2 *map[string]int = &m0 var m3 map[string]int...
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 allowed and disallowed conversions. // Does not compile. package main // everything here is legal except the ERROR line var c chan i...
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 of basic recover functionality. package main import "runtime" func main() { test1() test1WithClosures() test2() test3() test4() test5(...
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
// $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
// 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 illegal composite literals are detected. // Does not compile. package main var m map[int][3]int func f() [3]int func fp() *[3...
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
//line x7.go:4 package main func F7() {}
Go
//line x2.go:4 package main func F2() {}
Go
//line x6.go:4 package main func F6() {}
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 x10.go:4 package main func F10() {}
Go
//line x16.go:4 package main func F16() {}
Go
//line x5.go:4 package main func F5() {}
Go
//line x18.go:4 package main func F18() {}
Go
//line x1.go:4 package main func F1() {}
Go
//line x14.go:4 package main func F14() {}
Go
//line x8.go:4 package main func F8() {}
Go
//line x9.go:4 package main func F9() {}
Go
//line x19.go:4 package main func F19() {}
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 x4.go:4 package main func F4() {}
Go
//line x15.go:4 package main func F15() {}
Go
//line x12.go:4 package main func F12() {}
Go
//line x11.go:4 package main func F11() {}
Go
//line x13.go:4 package main func F13() {}
Go
//line x17.go:4 package main func F17() {}
Go
//line x3.go:4 package main func F3() {}
Go
//line x20.go:4 package main func F20() {}
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 overflow is detected when using numeric constants. // Does not compile. package main type I interface{} const ( // assume all types...
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 boolean and numeric constants. package main const ( c0 = 0 cm1 = -1 chuge = 1 << 100 chuge_1 = chuge - 1 c1 = chuge >> 100 c3div2...
Go
// errchk -0 $G -m -l $D/$F.go // 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, using compiler diagnostic flags, that the escape analysis is working. // Compiles but does not run. Inlining is disab...
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 pointers and interface types cannot be method receivers. // Does not compile. package main type T struct { a int } type P *T ty...
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 concurrency primitives: classical inefficient concurrent prime sieve. // Generate primes up to 100 using channels, checking the results. // Thi...
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 that a select statement proceeds when a value is ready. package main func f() *int { println("BUG: called f") return new(int) } func main() ...
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 the semantics of the select statement // for basic empty/non-empty cases. package main import "time" const always = "function did not" const ...
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 channel operations that test for blocking. // Use several sizes and types of operands. package main import "runtime" import "time" func i32re...
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 select. package main var counter uint var shift uint func GetValue() uint { counter++ return 1 << shift } func Send(a, b chan uint)...
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 various parsing cases that are a little // different now that send is a statement, not a expression. package main func main() { chanchan() ...
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 for select: Issue 2075 // A bug in select corrupts channel queues of failed cases // if there are multiple waiters on those channels and the //...
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 concurrency primitives: power series. // Like powser1.go but uses channels of interfaces. // Has not been cleaned up as much as powser1.go, to ...
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 that selects do not consume undue memory. package main import "runtime" func sender(c chan int, n int) { for i := 0; i < n; i++ { c <- 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 the situation in which two cases of a select can // both end up running. See http://codereview.appspot.com/180068. package main import ( "fla...
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 select when discarding a value. package main import "runtime" func recv1(c <-chan int) { <-c } func recv2(c <-chan int) { select { case ...
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. // Torture test for goroutines. // Make a lot of goroutines, threaded together, and tear them down cleanly. package main import ( "os" "strconv" ) ...
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 making channels of a zero-sized type. package main func main() { _ = make(chan [0]byte) _ = make(chan [0]byte, 1) _ = make(chan struct{}) ...
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 concurrency primitives: prime sieve of Eratosthenes. // Generate primes up to 100 using channels, checking the results. // This sieve is Eratos...
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 concurrency primitives: power series. // Power series package // A power series is a channel, along which flow rational // coefficients. A den...
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 various correct and incorrect permutations of send-only, // receive-only, and bidirectional channels. // Does not compile. package 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 that unbuffered channels act as pure fifos. package main import "os" const N = 10 func AsynchFifo() { ch := make(chan int, N) for i := 0; ...
Go
// runoutput // 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. // Generate test of channel operations and simple selects. // The output of this program is compiled and run to do the // actual test. // Each t...
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
// cmpout // 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 big numbers work as constants and print can print them. package main func main() { print(-(1<<63), "\n") print((1<<63)-1, "\n") }
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 predeclared names can be redeclared by the user. package main import "fmt" func main() { n := append + bool + byte + comple...
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. // Test map declarations of many types, including erroneous ones. // Does not compile. package main func main() {} type v bool var ( // val...
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
// 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 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
// compile // 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 unsafe.Sizeof, unsafe.Alignof, and unsafe.Offsetof all return uintptr. package main import "unsafe" type T struct { X int } var t T f...
Go
// run cmplxdivide1.go // 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. // Driver for complex division table defined in cmplxdivide1.go package main import ( "fmt" "math" "math/cmplx" ) type Test struc...
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 behavior of closures. package main import "runtime" var c = make(chan int) func check(a []int) { for i := 0; i < len(a); i++ { n := <...
Go
// compile // 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 a comment ending a source file does not need a final newline. // Compiles but does not run. package eof1 // No newline at the end of...
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 typed integer constants. package main import "fmt" type T int func (t T) String() string { return fmt.Sprintf("T%d", int(t)) } const ( A T...
Go
// 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 import ( "fmt" "math/rand" ) const ( win = 100 // The winning score in a game of Pig gamesPerSeries = 10 // The number of games p...
Go
// 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. /* Generating random text: a Markov chain algorithm Based on the program presented in the "Design and Implementation" chapter of The Practice of Programming (...
Go