summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
committerOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
commit3e45412327a2654a77944249962b3652e6142299 (patch)
treebc3bf69452afa055423cbe0c5cfa8ca357df6ccf /test
parentc533680039762cacbc37db8dc7eed074c3e497be (diff)
downloadgolang-3e45412327a2654a77944249962b3652e6142299.tar.gz
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'test')
-rw-r--r--test/64bit.go302
-rw-r--r--test/append.go227
-rw-r--r--test/arm-pass.txt444
-rw-r--r--test/assign.go48
-rw-r--r--test/assign1.go110
-rw-r--r--test/bench/fannkuch-parallel.go2
-rw-r--r--test/bench/fasta.c4
-rw-r--r--test/bench/fasta.go47
-rw-r--r--test/bench/k-nucleotide-parallel.go2
-rw-r--r--test/bench/pidigits.go8
-rw-r--r--test/bench/regex-dna-parallel.go4
-rw-r--r--test/bench/regex-dna.go2
-rw-r--r--test/bench/timing.log108
-rwxr-xr-xtest/bench/timing.sh42
-rw-r--r--test/bigalg.go86
-rw-r--r--test/blank.go62
-rw-r--r--test/blank1.go4
-rw-r--r--test/chan/fifo.go26
-rw-r--r--test/chan/goroutines.go32
-rw-r--r--test/chan/nonblock.go98
-rw-r--r--test/chan/perm.go68
-rw-r--r--test/chan/powser1.go579
-rw-r--r--test/chan/powser2.go585
-rw-r--r--test/chan/select3.go203
-rw-r--r--test/chan/select4.go25
-rw-r--r--test/char_lit.go7
-rw-r--r--test/char_lit1.go16
-rw-r--r--test/closedchan.go98
-rw-r--r--test/closure.go11
-rw-r--r--test/cmp1.go54
-rw-r--r--test/cmp2.go6
-rw-r--r--test/cmp3.go6
-rw-r--r--test/cmp4.go8
-rw-r--r--test/cmp5.go8
-rw-r--r--test/cmp6.go42
-rw-r--r--test/cmplx.go1
-rw-r--r--test/cmplxdivide.go5
-rw-r--r--test/complit.go44
-rw-r--r--test/compos.go8
-rw-r--r--test/const.go164
-rw-r--r--test/const1.go114
-rw-r--r--test/const2.go2
-rw-r--r--test/const3.go6
-rw-r--r--test/convert3.go4
-rw-r--r--test/convlit.go40
-rw-r--r--test/copy.go61
-rw-r--r--test/ddd.go34
-rw-r--r--test/ddd1.go19
-rw-r--r--test/decl.go30
-rw-r--r--test/declbad.go42
-rw-r--r--test/defer.go2
-rw-r--r--test/env.go17
-rw-r--r--test/eof.go9
-rw-r--r--test/eof1.go (renamed from test/syntax/slice.go)4
-rwxr-xr-xtest/errchk100
-rw-r--r--test/escape.go158
-rw-r--r--test/fixedbugs/bug045.go2
-rw-r--r--test/fixedbugs/bug059.go2
-rw-r--r--test/fixedbugs/bug146.go2
-rw-r--r--test/fixedbugs/bug195.go4
-rw-r--r--test/fixedbugs/bug206.go4
-rw-r--r--test/fixedbugs/bug243.go8
-rw-r--r--test/fixedbugs/bug251.go6
-rw-r--r--test/fixedbugs/bug252.go4
-rw-r--r--test/fixedbugs/bug255.go6
-rw-r--r--test/fixedbugs/bug260.go (renamed from test/bugs/bug260.go)18
-rw-r--r--test/fixedbugs/bug273.go28
-rw-r--r--test/fixedbugs/bug274.go (renamed from test/bugs/bug274.go)0
-rw-r--r--test/fixedbugs/bug278.go8
-rw-r--r--test/fixedbugs/bug284.go70
-rw-r--r--test/fixedbugs/bug286.go (renamed from test/bugs/bug286.go)0
-rw-r--r--test/fixedbugs/bug289.go26
-rw-r--r--test/fixedbugs/bug290.go15
-rw-r--r--test/fixedbugs/bug291.go23
-rw-r--r--test/fixedbugs/bug292.go22
-rw-r--r--test/fixedbugs/bug293.go37
-rw-r--r--test/fixedbugs/bug294.go79
-rw-r--r--test/fixedbugs/bug295.go17
-rw-r--r--test/fixedbugs/bug296.go88
-rw-r--r--test/fixedbugs/bug297.go15
-rw-r--r--test/fixedbugs/bug298.go11
-rw-r--r--test/fixedbugs/bug299.go27
-rw-r--r--test/fixedbugs/bug300.go29
-rw-r--r--test/fixedbugs/bug301.go18
-rw-r--r--test/fixedbugs/bug302.dir/main.go12
-rw-r--r--test/fixedbugs/bug302.dir/p.go1011
-rw-r--r--test/fixedbugs/bug302.go6
-rw-r--r--test/fixedbugs/bug303.go37
-rw-r--r--test/fixedbugs/bug304.go18
-rw-r--r--test/fixedbugs/bug305.go24
-rw-r--r--test/fixedbugs/bug306.dir/p1.go9
-rw-r--r--test/fixedbugs/bug306.dir/p2.go8
-rw-r--r--test/fixedbugs/bug306.go7
-rw-r--r--test/fixedbugs/bug307.go15
-rw-r--r--test/fixedbugs/bug308.go19
-rw-r--r--test/fixedbugs/bug309.go19
-rw-r--r--test/fixedbugs/bug310.go20
-rw-r--r--test/fixedbugs/bug311.go20
-rw-r--r--test/fixedbugs/bug312.go22
-rw-r--r--test/fixedbugs/bug313.dir/a.go11
-rw-r--r--test/fixedbugs/bug313.dir/b.go11
-rw-r--r--test/fixedbugs/bug313.go19
-rw-r--r--test/fixedbugs/bug314.go31
-rw-r--r--test/fixedbugs/bug315.go18
-rw-r--r--test/fixedbugs/bug316.go17
-rw-r--r--test/fixedbugs/bug317.go16
-rw-r--r--test/float_lit.go224
-rw-r--r--test/floatcmp.go18
-rw-r--r--test/for.go42
-rw-r--r--test/func.go74
-rw-r--r--test/func1.go4
-rw-r--r--test/func2.go24
-rw-r--r--test/func3.go14
-rw-r--r--test/func4.go4
-rw-r--r--test/garbage/Makefile2
-rw-r--r--test/garbage/parser.go8
-rw-r--r--test/gc.go2
-rw-r--r--test/gc1.go4
-rw-r--r--test/golden-arm.out110
-rw-r--r--test/golden.out14
-rwxr-xr-xtest/hashmap.go123
-rw-r--r--test/helloworld.go2
-rw-r--r--test/if.go100
-rw-r--r--test/if1.go4
-rw-r--r--test/import.go8
-rw-r--r--test/import1.go4
-rw-r--r--test/index.go224
-rw-r--r--test/indirect1.go2
-rw-r--r--test/initialize.go12
-rw-r--r--test/initializerr.go10
-rw-r--r--test/initsyscall.go4
-rw-r--r--test/int_lit.go6
-rw-r--r--test/interface/bigdata.go52
-rw-r--r--test/interface/convert1.go18
-rw-r--r--test/interface/convert2.go18
-rw-r--r--test/interface/embed.go63
-rw-r--r--test/interface/embed0.go24
-rw-r--r--test/interface/embed1.go50
-rw-r--r--test/interface/embed2.go70
-rw-r--r--test/interface/explicit.go12
-rw-r--r--test/interface/fail.go12
-rw-r--r--test/interface/fake.go78
-rw-r--r--test/interface/receiver.go4
-rw-r--r--test/interface/returntype.go6
-rw-r--r--test/interface/struct.go152
-rw-r--r--test/iota.go156
-rw-r--r--test/ken/array.go8
-rw-r--r--test/ken/convert.go431
-rw-r--r--test/ken/cplx4.go2
-rw-r--r--test/ken/slicearray.go24
-rw-r--r--test/ken/sliceslice.go20
-rw-r--r--test/literal.go356
-rw-r--r--test/mallocrand.go10
-rw-r--r--test/mallocrep.go3
-rw-r--r--test/map.go412
-rw-r--r--test/method.go24
-rw-r--r--test/method1.go8
-rw-r--r--test/method2.go19
-rw-r--r--test/named1.go2
-rw-r--r--test/nil.go36
-rw-r--r--test/nilptr/arrayindex.go7
-rw-r--r--test/nilptr/arrayindex1.go9
-rw-r--r--test/nilptr/arraytoslice.go11
-rw-r--r--test/nilptr/arraytoslice1.go11
-rw-r--r--test/nilptr/arraytoslice2.go13
-rw-r--r--test/nilptr/slicearray.go9
-rw-r--r--test/nilptr/structfield.go13
-rw-r--r--test/nilptr/structfield1.go13
-rw-r--r--test/nilptr/structfield2.go15
-rw-r--r--test/nilptr/structfieldaddr.go13
-rw-r--r--test/nul1.go6
-rw-r--r--test/parentype.go12
-rw-r--r--test/peano.go13
-rw-r--r--test/printbig.go2
-rw-r--r--test/range.go199
-rw-r--r--test/recover2.go10
-rw-r--r--test/recover3.go17
-rwxr-xr-xtest/run39
-rwxr-xr-xtest/run-arm102
-rw-r--r--test/runtime.go2
-rw-r--r--test/sieve.go20
-rw-r--r--test/sigchld.go5
-rw-r--r--test/sinit.go8
-rw-r--r--test/solitaire.go119
-rw-r--r--test/string_lit.go54
-rw-r--r--test/stringrange.go54
-rw-r--r--test/switch.go158
-rw-r--r--test/switch1.go6
-rw-r--r--test/syntax/chan.go17
-rw-r--r--test/syntax/topexpr.go6
-rw-r--r--test/syntax/vareq.go2
-rw-r--r--test/syntax/vareq1.go2
-rw-r--r--test/test0.go64
-rw-r--r--test/turing.go51
-rw-r--r--test/typeswitch.go78
-rw-r--r--test/undef.go10
-rw-r--r--test/utf.go60
-rw-r--r--test/varerr.go4
-rw-r--r--test/zerodivide.go44
199 files changed, 6867 insertions, 3701 deletions
diff --git a/test/64bit.go b/test/64bit.go
index b014e546c..9e91a97fd 100644
--- a/test/64bit.go
+++ b/test/64bit.go
@@ -15,9 +15,9 @@
package main
import (
- "bufio";
- "fmt";
- "os";
+ "bufio"
+ "fmt"
+ "os"
)
var bout *bufio.Writer
@@ -27,19 +27,19 @@ var bout *bufio.Writer
// if the compiler has buggy or missing 64-bit support.
type Uint64 struct {
- hi uint32;
- lo uint32;
+ hi uint32
+ lo uint32
}
type Int64 struct {
- hi int32;
- lo uint32;
+ hi int32
+ lo uint32
}
func (a Uint64) Int64() (c Int64) {
- c.hi = int32(a.hi);
- c.lo = a.lo;
- return;
+ c.hi = int32(a.hi)
+ c.lo = a.lo
+ return
}
func (a Uint64) Cmp(b Uint64) int {
@@ -53,80 +53,80 @@ func (a Uint64) Cmp(b Uint64) int {
case a.lo > b.lo:
return 1
}
- return 0;
+ return 0
}
func (a Uint64) LeftShift(b uint) (c Uint64) {
switch {
case b >= 64:
- c.hi = 0;
- c.lo = 0;
+ c.hi = 0
+ c.lo = 0
case b >= 32:
- c.hi = a.lo << (b - 32);
- c.lo = 0;
+ c.hi = a.lo << (b - 32)
+ c.lo = 0
default:
- c.hi = a.hi<<b | a.lo>>(32-b);
- c.lo = a.lo << b;
+ c.hi = a.hi<<b | a.lo>>(32-b)
+ c.lo = a.lo << b
}
- return;
+ return
}
func (a Uint64) RightShift(b uint) (c Uint64) {
switch {
case b >= 64:
- c.hi = 0;
- c.lo = a.hi;
+ c.hi = 0
+ c.lo = a.hi
case b >= 32:
- c.hi = 0;
- c.lo = a.hi >> (b - 32);
+ c.hi = 0
+ c.lo = a.hi >> (b - 32)
default:
- c.hi = a.hi >> b;
- c.lo = a.hi<<(32-b) | a.lo>>b;
+ c.hi = a.hi >> b
+ c.lo = a.hi<<(32-b) | a.lo>>b
}
- return;
+ return
}
func (a Uint64) LeftShift64(b Uint64) (c Uint64) {
if b.hi != 0 || b.lo >= 64 {
return
}
- return a.LeftShift(uint(b.lo));
+ return a.LeftShift(uint(b.lo))
}
func (a Uint64) RightShift64(b Uint64) (c Uint64) {
if b.hi != 0 || b.lo >= 64 {
return
}
- return a.RightShift(uint(b.lo));
+ return a.RightShift(uint(b.lo))
}
func (a Uint64) Plus(b Uint64) (c Uint64) {
- var carry uint32;
+ var carry uint32
if c.lo = a.lo + b.lo; c.lo < a.lo {
carry = 1
}
- c.hi = a.hi + b.hi + carry;
- return;
+ c.hi = a.hi + b.hi + carry
+ return
}
func (a Uint64) Minus(b Uint64) (c Uint64) {
- var borrow uint32;
+ var borrow uint32
if c.lo = a.lo - b.lo; c.lo > a.lo {
borrow = 1
}
- c.hi = a.hi - b.hi - borrow;
- return;
+ c.hi = a.hi - b.hi - borrow
+ return
}
func (a Uint64) Neg() (c Uint64) {
- var zero Uint64;
- return zero.Minus(a);
+ var zero Uint64
+ return zero.Minus(a)
}
func (a Uint64) Com() (c Uint64) {
- c.hi = ^a.hi;
- c.lo = ^a.lo;
- return;
+ c.hi = ^a.hi
+ c.lo = ^a.lo
+ return
}
func (a Uint64) Len() int {
@@ -144,7 +144,7 @@ func (a Uint64) Len() int {
}
}
}
- return 0;
+ return 0
}
func (a Uint64) HasBit(b uint) bool {
@@ -154,7 +154,7 @@ func (a Uint64) HasBit(b uint) bool {
case b >= 32:
return a.hi&(1<<(b-32)) != 0
}
- return a.lo&(1<<b) != 0;
+ return a.lo&(1<<b) != 0
}
func (a Uint64) Times(b Uint64) (c Uint64) {
@@ -163,56 +163,56 @@ func (a Uint64) Times(b Uint64) (c Uint64) {
c = c.Plus(a.LeftShift(i))
}
}
- return;
+ return
}
func (a Uint64) DivMod(b Uint64) (quo, rem Uint64) {
- n := a.Len() - b.Len();
+ n := a.Len() - b.Len()
if n >= 0 {
- b = b.LeftShift(uint(n));
+ b = b.LeftShift(uint(n))
for i := 0; i <= n; i++ {
- quo = quo.LeftShift(1);
+ quo = quo.LeftShift(1)
if b.Cmp(a) <= 0 { // b <= a
- quo.lo |= 1;
- a = a.Minus(b);
+ quo.lo |= 1
+ a = a.Minus(b)
}
- b = b.RightShift(1);
+ b = b.RightShift(1)
}
}
- rem = a;
- return;
+ rem = a
+ return
}
func (a Uint64) And(b Uint64) (c Uint64) {
- c.hi = a.hi & b.hi;
- c.lo = a.lo & b.lo;
- return;
+ c.hi = a.hi & b.hi
+ c.lo = a.lo & b.lo
+ return
}
func (a Uint64) AndNot(b Uint64) (c Uint64) {
- c.hi = a.hi &^ b.hi;
- c.lo = a.lo &^ b.lo;
- return;
+ c.hi = a.hi &^ b.hi
+ c.lo = a.lo &^ b.lo
+ return
}
func (a Uint64) Or(b Uint64) (c Uint64) {
- c.hi = a.hi | b.hi;
- c.lo = a.lo | b.lo;
- return;
+ c.hi = a.hi | b.hi
+ c.lo = a.lo | b.lo
+ return
}
func (a Uint64) Xor(b Uint64) (c Uint64) {
- c.hi = a.hi ^ b.hi;
- c.lo = a.lo ^ b.lo;
- return;
+ c.hi = a.hi ^ b.hi
+ c.lo = a.lo ^ b.lo
+ return
}
func (a Uint64) String() string { return fmt.Sprintf("%#x%08x", a.hi, a.lo) }
func (a Int64) Uint64() (c Uint64) {
- c.hi = uint32(a.hi);
- c.lo = a.lo;
- return;
+ c.hi = uint32(a.hi)
+ c.lo = a.lo
+ return
}
func (a Int64) Cmp(b Int64) int {
@@ -229,7 +229,7 @@ func (a Int64) Cmp(b Int64) int {
case a.lo > b.lo:
return 1
}
- return 0;
+ return 0
}
func (a Int64) LeftShift(b uint) (c Int64) { return a.Uint64().LeftShift(b).Int64() }
@@ -237,30 +237,30 @@ func (a Int64) LeftShift(b uint) (c Int64) { return a.Uint64().LeftShift(b).Int6
func (a Int64) RightShift(b uint) (c Int64) {
switch {
case b >= 64:
- c.hi = a.hi >> 31; // sign extend
- c.lo = uint32(c.hi);
+ c.hi = a.hi >> 31 // sign extend
+ c.lo = uint32(c.hi)
case b >= 32:
- c.hi = a.hi >> 31; // sign extend
- c.lo = uint32(a.hi >> (b - 32));
+ c.hi = a.hi >> 31 // sign extend
+ c.lo = uint32(a.hi >> (b - 32))
default:
- c.hi = a.hi >> b;
- c.lo = uint32(a.hi<<(32-b)) | a.lo>>b;
+ c.hi = a.hi >> b
+ c.lo = uint32(a.hi<<(32-b)) | a.lo>>b
}
- return;
+ return
}
func (a Int64) LeftShift64(b Uint64) (c Int64) {
if b.hi != 0 || b.lo >= 64 {
return
}
- return a.LeftShift(uint(b.lo));
+ return a.LeftShift(uint(b.lo))
}
func (a Int64) RightShift64(b Uint64) (c Int64) {
if b.hi != 0 || b.lo >= 64 {
return a.RightShift(64)
}
- return a.RightShift(uint(b.lo));
+ return a.RightShift(uint(b.lo))
}
func (a Int64) Plus(b Int64) (c Int64) { return a.Uint64().Plus(b.Uint64()).Int64() }
@@ -274,23 +274,23 @@ func (a Int64) Com() (c Int64) { return a.Uint64().Com().Int64() }
func (a Int64) Times(b Int64) (c Int64) { return a.Uint64().Times(b.Uint64()).Int64() }
func (a Int64) DivMod(b Int64) (quo Int64, rem Int64) {
- var zero Int64;
+ var zero Int64
- quoSign := +1;
- remSign := +1;
+ quoSign := +1
+ remSign := +1
if a.Cmp(zero) < 0 {
- quoSign = -1;
- remSign = -1;
- a = a.Neg();
+ quoSign = -1
+ remSign = -1
+ a = a.Neg()
}
if b.Cmp(zero) < 0 {
- quoSign = -quoSign;
- b = b.Neg();
+ quoSign = -quoSign
+ b = b.Neg()
}
- q, r := a.Uint64().DivMod(b.Uint64());
- quo = q.Int64();
- rem = r.Int64();
+ q, r := a.Uint64().DivMod(b.Uint64())
+ quo = q.Int64()
+ rem = r.Int64()
if quoSign < 0 {
quo = quo.Neg()
@@ -298,7 +298,7 @@ func (a Int64) DivMod(b Int64) (quo Int64, rem Int64) {
if remSign < 0 {
rem = rem.Neg()
}
- return;
+ return
}
func (a Int64) And(b Int64) (c Int64) { return a.Uint64().And(b.Uint64()).Int64() }
@@ -313,7 +313,7 @@ func (a Int64) String() string {
if a.hi < 0 {
return fmt.Sprintf("-%s", a.Neg().Uint64())
}
- return a.Uint64().String();
+ return a.Uint64().String()
}
var int64Values = []Int64{
@@ -507,56 +507,56 @@ const prolog = "\n" +
"\n"
func varTests() {
- fmt.Fprint(bout, prolog);
+ fmt.Fprint(bout, prolog)
for _, a := range int64Values {
- fmt.Fprintf(bout, "func test%v() {\n", ntest);
- ntest++;
- fmt.Fprintf(bout, "\ttestInt64Unary(%v, %v, %v, %v);\n", a, a, a.Com(), a.Neg());
+ fmt.Fprintf(bout, "func test%v() {\n", ntest)
+ ntest++
+ fmt.Fprintf(bout, "\ttestInt64Unary(%v, %v, %v, %v);\n", a, a, a.Com(), a.Neg())
for _, b := range int64Values {
- var div, mod Int64;
- dodiv := false;
- var zero Int64;
+ var div, mod Int64
+ dodiv := false
+ var zero Int64
if b.Cmp(zero) != 0 { // b != 0
// Can't divide by zero but also can't divide -0x8000...000 by -1.
- var bigneg = Int64{-0x80000000, 0};
- var minus1 = Int64{-1, ^uint32(0)};
+ var bigneg = Int64{-0x80000000, 0}
+ var minus1 = Int64{-1, ^uint32(0)}
if a.Cmp(bigneg) != 0 || b.Cmp(minus1) != 0 { // a != -1<<63 || b != -1
- div, mod = a.DivMod(b);
- dodiv = true;
+ div, mod = a.DivMod(b)
+ dodiv = true
}
}
fmt.Fprintf(bout, "\ttestInt64Binary(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n",
a, b, a.Plus(b), a.Minus(b), a.Times(b), div, mod,
- a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv);
+ a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv)
}
for _, b := range shiftValues {
fmt.Fprintf(bout, "\ttestInt64Shift(%v, %v, %v, %v);\n",
a, b, a.LeftShift64(b), a.RightShift64(b))
}
- fmt.Fprintf(bout, "}\n");
+ fmt.Fprintf(bout, "}\n")
}
for _, a := range uint64Values {
- fmt.Fprintf(bout, "func test%v() {\n", ntest);
- ntest++;
- fmt.Fprintf(bout, "\ttestUint64Unary(%v, %v, %v, %v);\n", a, a, a.Com(), a.Neg());
+ fmt.Fprintf(bout, "func test%v() {\n", ntest)
+ ntest++
+ fmt.Fprintf(bout, "\ttestUint64Unary(%v, %v, %v, %v);\n", a, a, a.Com(), a.Neg())
for _, b := range uint64Values {
- var div, mod Uint64;
- dodiv := false;
- var zero Uint64;
+ var div, mod Uint64
+ dodiv := false
+ var zero Uint64
if b.Cmp(zero) != 0 { // b != 0
- div, mod = a.DivMod(b);
- dodiv = true;
+ div, mod = a.DivMod(b)
+ dodiv = true
}
fmt.Fprintf(bout, "\ttestUint64Binary(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n",
a, b, a.Plus(b), a.Minus(b), a.Times(b), div, mod,
- a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv);
+ a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv)
}
for _, b := range shiftValues {
fmt.Fprintf(bout, "\ttestUint64Shift(%v, %v, %v, %v);\n",
a, b, a.LeftShift64(b), a.RightShift64(b))
}
- fmt.Fprintf(bout, "}\n");
+ fmt.Fprintf(bout, "}\n")
}
}
@@ -622,88 +622,88 @@ const shiftConstR = "func test%vShiftR%v(a, left, right %v) {\n" +
func constTests() {
for i, a := range int64Values {
- fmt.Fprintf(bout, binaryConstL, "Int64", i, "int64", "int64", a, "int64");
- fmt.Fprintf(bout, binaryConstR, "Int64", i, "int64", "int64", a, "int64");
- fmt.Fprintf(bout, shiftConstL, "Int64", i, "int64", "int64", a, "int64");
+ fmt.Fprintf(bout, binaryConstL, "Int64", i, "int64", "int64", a, "int64")
+ fmt.Fprintf(bout, binaryConstR, "Int64", i, "int64", "int64", a, "int64")
+ fmt.Fprintf(bout, shiftConstL, "Int64", i, "int64", "int64", a, "int64")
}
for i, a := range uint64Values {
- fmt.Fprintf(bout, binaryConstL, "Uint64", i, "uint64", "uint64", a, "uint64");
- fmt.Fprintf(bout, binaryConstR, "Uint64", i, "uint64", "uint64", a, "uint64");
- fmt.Fprintf(bout, shiftConstL, "Uint64", i, "uint64", "uint64", a, "uint64");
+ fmt.Fprintf(bout, binaryConstL, "Uint64", i, "uint64", "uint64", a, "uint64")
+ fmt.Fprintf(bout, binaryConstR, "Uint64", i, "uint64", "uint64", a, "uint64")
+ fmt.Fprintf(bout, shiftConstL, "Uint64", i, "uint64", "uint64", a, "uint64")
}
for i, a := range shiftValues {
- fmt.Fprintf(bout, shiftConstR, "Int64", i, "int64", a, "int64");
- fmt.Fprintf(bout, shiftConstR, "Uint64", i, "uint64", a, "uint64");
+ fmt.Fprintf(bout, shiftConstR, "Int64", i, "int64", a, "int64")
+ fmt.Fprintf(bout, shiftConstR, "Uint64", i, "uint64", a, "uint64")
}
for i, a := range int64Values {
- fmt.Fprintf(bout, "func test%v() {\n", ntest);
- ntest++;
+ fmt.Fprintf(bout, "func test%v() {\n", ntest)
+ ntest++
for j, b := range int64Values {
- var div, mod Int64;
- dodiv := false;
- var zero Int64;
+ var div, mod Int64
+ dodiv := false
+ var zero Int64
if b.Cmp(zero) != 0 { // b != 0
// Can't divide by zero but also can't divide -0x8000...000 by -1.
- var bigneg = Int64{-0x80000000, 0};
- var minus1 = Int64{-1, ^uint32(0)};
+ var bigneg = Int64{-0x80000000, 0}
+ var minus1 = Int64{-1, ^uint32(0)}
if a.Cmp(bigneg) != 0 || b.Cmp(minus1) != 0 { // a != -1<<63 || b != -1
- div, mod = a.DivMod(b);
- dodiv = true;
+ div, mod = a.DivMod(b)
+ dodiv = true
}
}
fmt.Fprintf(bout, "\ttestInt64BinaryL%v(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n",
i, b, a.Plus(b), a.Minus(b), a.Times(b), div, mod,
- a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv);
+ a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv)
fmt.Fprintf(bout, "\ttestInt64BinaryR%v(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n",
j, a, a.Plus(b), a.Minus(b), a.Times(b), div, mod,
- a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv);
+ a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv)
}
for j, b := range shiftValues {
fmt.Fprintf(bout, "\ttestInt64ShiftL%v(%v, %v, %v);\n",
- i, b, a.LeftShift64(b), a.RightShift64(b));
+ i, b, a.LeftShift64(b), a.RightShift64(b))
fmt.Fprintf(bout, "\ttestInt64ShiftR%v(%v, %v, %v);\n",
- j, a, a.LeftShift64(b), a.RightShift64(b));
+ j, a, a.LeftShift64(b), a.RightShift64(b))
}
- fmt.Fprintf(bout, "}\n");
+ fmt.Fprintf(bout, "}\n")
}
for i, a := range uint64Values {
- fmt.Fprintf(bout, "func test%v() {\n", ntest);
- ntest++;
+ fmt.Fprintf(bout, "func test%v() {\n", ntest)
+ ntest++
for j, b := range uint64Values {
- var div, mod Uint64;
- dodiv := false;
- var zero Uint64;
+ var div, mod Uint64
+ dodiv := false
+ var zero Uint64
if b.Cmp(zero) != 0 { // b != 0
- div, mod = a.DivMod(b);
- dodiv = true;
+ div, mod = a.DivMod(b)
+ dodiv = true
}
fmt.Fprintf(bout, "\ttestUint64BinaryL%v(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n",
i, b, a.Plus(b), a.Minus(b), a.Times(b), div, mod,
- a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv);
+ a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv)
fmt.Fprintf(bout, "\ttestUint64BinaryR%v(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n",
j, a, a.Plus(b), a.Minus(b), a.Times(b), div, mod,
- a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv);
+ a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv)
}
for j, b := range shiftValues {
fmt.Fprintf(bout, "\ttestUint64ShiftL%v(%v, %v, %v);\n",
- i, b, a.LeftShift64(b), a.RightShift64(b));
+ i, b, a.LeftShift64(b), a.RightShift64(b))
fmt.Fprintf(bout, "\ttestUint64ShiftR%v(%v, %v, %v);\n",
- j, a, a.LeftShift64(b), a.RightShift64(b));
+ j, a, a.LeftShift64(b), a.RightShift64(b))
}
- fmt.Fprintf(bout, "}\n");
+ fmt.Fprintf(bout, "}\n")
}
}
func main() {
- bout = bufio.NewWriter(os.Stdout);
- varTests();
- constTests();
+ bout = bufio.NewWriter(os.Stdout)
+ varTests()
+ constTests()
- fmt.Fprintf(bout, "func main() {\n");
+ fmt.Fprintf(bout, "func main() {\n")
for i := 0; i < ntest; i++ {
fmt.Fprintf(bout, "\ttest%v();\n", i)
}
- fmt.Fprintf(bout, "\tif !ok { os.Exit(1) }\n");
- fmt.Fprintf(bout, "}\n");
- bout.Flush();
+ fmt.Fprintf(bout, "\tif !ok { os.Exit(1) }\n")
+ fmt.Fprintf(bout, "}\n")
+ bout.Flush()
}
diff --git a/test/append.go b/test/append.go
new file mode 100644
index 000000000..17c665227
--- /dev/null
+++ b/test/append.go
@@ -0,0 +1,227 @@
+// $G $F.go && $L $F.$A && ./$A.out
+
+// 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 append()
+
+package main
+
+import (
+ "fmt"
+ "reflect"
+)
+
+
+func verify(name string, result, expected interface{}) {
+ if !reflect.DeepEqual(result, expected) {
+ panic(name)
+ }
+}
+
+
+func main() {
+ for _, t := range tests {
+ verify(t.name, t.result, t.expected)
+ }
+ verifyStruct()
+ verifyInterface()
+}
+
+
+var tests = []struct {
+ name string
+ result, expected interface{}
+}{
+ {"bool a", append([]bool{}), []bool{}},
+ {"bool b", append([]bool{}, true), []bool{true}},
+ {"bool c", append([]bool{}, true, false, true, true), []bool{true, false, true, true}},
+
+ {"bool d", append([]bool{true, false, true}), []bool{true, false, true}},
+ {"bool e", append([]bool{true, false, true}, false), []bool{true, false, true, false}},
+ {"bool f", append([]bool{true, false, true}, false, false, false), []bool{true, false, true, false, false, false}},
+
+ {"bool g", append([]bool{}, []bool{true}...), []bool{true}},
+ {"bool h", append([]bool{}, []bool{true, false, true, false}...), []bool{true, false, true, false}},
+
+ {"bool i", append([]bool{true, false, true}, []bool{true}...), []bool{true, false, true, true}},
+ {"bool j", append([]bool{true, false, true}, []bool{true, true, true}...), []bool{true, false, true, true, true, true}},
+
+
+ {"byte a", append([]byte{}), []byte{}},
+ {"byte b", append([]byte{}, 0), []byte{0}},
+ {"byte c", append([]byte{}, 0, 1, 2, 3), []byte{0, 1, 2, 3}},
+
+ {"byte d", append([]byte{0, 1, 2}), []byte{0, 1, 2}},
+ {"byte e", append([]byte{0, 1, 2}, 3), []byte{0, 1, 2, 3}},
+ {"byte f", append([]byte{0, 1, 2}, 3, 4, 5), []byte{0, 1, 2, 3, 4, 5}},
+
+ {"byte g", append([]byte{}, []byte{0}...), []byte{0}},
+ {"byte h", append([]byte{}, []byte{0, 1, 2, 3}...), []byte{0, 1, 2, 3}},
+
+ {"byte i", append([]byte{0, 1, 2}, []byte{3}...), []byte{0, 1, 2, 3}},
+ {"byte j", append([]byte{0, 1, 2}, []byte{3, 4, 5}...), []byte{0, 1, 2, 3, 4, 5}},
+
+
+ {"int16 a", append([]int16{}), []int16{}},
+ {"int16 b", append([]int16{}, 0), []int16{0}},
+ {"int16 c", append([]int16{}, 0, 1, 2, 3), []int16{0, 1, 2, 3}},
+
+ {"int16 d", append([]int16{0, 1, 2}), []int16{0, 1, 2}},
+ {"int16 e", append([]int16{0, 1, 2}, 3), []int16{0, 1, 2, 3}},
+ {"int16 f", append([]int16{0, 1, 2}, 3, 4, 5), []int16{0, 1, 2, 3, 4, 5}},
+
+ {"int16 g", append([]int16{}, []int16{0}...), []int16{0}},
+ {"int16 h", append([]int16{}, []int16{0, 1, 2, 3}...), []int16{0, 1, 2, 3}},
+
+ {"int16 i", append([]int16{0, 1, 2}, []int16{3}...), []int16{0, 1, 2, 3}},
+ {"int16 j", append([]int16{0, 1, 2}, []int16{3, 4, 5}...), []int16{0, 1, 2, 3, 4, 5}},
+
+
+ {"uint32 a", append([]uint32{}), []uint32{}},
+ {"uint32 b", append([]uint32{}, 0), []uint32{0}},
+ {"uint32 c", append([]uint32{}, 0, 1, 2, 3), []uint32{0, 1, 2, 3}},
+
+ {"uint32 d", append([]uint32{0, 1, 2}), []uint32{0, 1, 2}},
+ {"uint32 e", append([]uint32{0, 1, 2}, 3), []uint32{0, 1, 2, 3}},
+ {"uint32 f", append([]uint32{0, 1, 2}, 3, 4, 5), []uint32{0, 1, 2, 3, 4, 5}},
+
+ {"uint32 g", append([]uint32{}, []uint32{0}...), []uint32{0}},
+ {"uint32 h", append([]uint32{}, []uint32{0, 1, 2, 3}...), []uint32{0, 1, 2, 3}},
+
+ {"uint32 i", append([]uint32{0, 1, 2}, []uint32{3}...), []uint32{0, 1, 2, 3}},
+ {"uint32 j", append([]uint32{0, 1, 2}, []uint32{3, 4, 5}...), []uint32{0, 1, 2, 3, 4, 5}},
+
+
+ {"float64 a", append([]float64{}), []float64{}},
+ {"float64 b", append([]float64{}, 0), []float64{0}},
+ {"float64 c", append([]float64{}, 0, 1, 2, 3), []float64{0, 1, 2, 3}},
+
+ {"float64 d", append([]float64{0, 1, 2}), []float64{0, 1, 2}},
+ {"float64 e", append([]float64{0, 1, 2}, 3), []float64{0, 1, 2, 3}},
+ {"float64 f", append([]float64{0, 1, 2}, 3, 4, 5), []float64{0, 1, 2, 3, 4, 5}},
+
+ {"float64 g", append([]float64{}, []float64{0}...), []float64{0}},
+ {"float64 h", append([]float64{}, []float64{0, 1, 2, 3}...), []float64{0, 1, 2, 3}},
+
+ {"float64 i", append([]float64{0, 1, 2}, []float64{3}...), []float64{0, 1, 2, 3}},
+ {"float64 j", append([]float64{0, 1, 2}, []float64{3, 4, 5}...), []float64{0, 1, 2, 3, 4, 5}},
+
+
+ {"complex128 a", append([]complex128{}), []complex128{}},
+ {"complex128 b", append([]complex128{}, 0), []complex128{0}},
+ {"complex128 c", append([]complex128{}, 0, 1, 2, 3), []complex128{0, 1, 2, 3}},
+
+ {"complex128 d", append([]complex128{0, 1, 2}), []complex128{0, 1, 2}},
+ {"complex128 e", append([]complex128{0, 1, 2}, 3), []complex128{0, 1, 2, 3}},
+ {"complex128 f", append([]complex128{0, 1, 2}, 3, 4, 5), []complex128{0, 1, 2, 3, 4, 5}},
+
+ {"complex128 g", append([]complex128{}, []complex128{0}...), []complex128{0}},
+ {"complex128 h", append([]complex128{}, []complex128{0, 1, 2, 3}...), []complex128{0, 1, 2, 3}},
+
+ {"complex128 i", append([]complex128{0, 1, 2}, []complex128{3}...), []complex128{0, 1, 2, 3}},
+ {"complex128 j", append([]complex128{0, 1, 2}, []complex128{3, 4, 5}...), []complex128{0, 1, 2, 3, 4, 5}},
+
+
+ {"string a", append([]string{}), []string{}},
+ {"string b", append([]string{}, "0"), []string{"0"}},
+ {"string c", append([]string{}, "0", "1", "2", "3"), []string{"0", "1", "2", "3"}},
+
+ {"string d", append([]string{"0", "1", "2"}), []string{"0", "1", "2"}},
+ {"string e", append([]string{"0", "1", "2"}, "3"), []string{"0", "1", "2", "3"}},
+ {"string f", append([]string{"0", "1", "2"}, "3", "4", "5"), []string{"0", "1", "2", "3", "4", "5"}},
+
+ {"string g", append([]string{}, []string{"0"}...), []string{"0"}},
+ {"string h", append([]string{}, []string{"0", "1", "2", "3"}...), []string{"0", "1", "2", "3"}},
+
+ {"string i", append([]string{"0", "1", "2"}, []string{"3"}...), []string{"0", "1", "2", "3"}},
+ {"string j", append([]string{"0", "1", "2"}, []string{"3", "4", "5"}...), []string{"0", "1", "2", "3", "4", "5"}},
+}
+
+
+func verifyStruct() {
+ type T struct {
+ a, b, c string
+ }
+ type S []T
+ e := make(S, 100)
+ for i := range e {
+ e[i] = T{"foo", fmt.Sprintf("%d", i), "bar"}
+ }
+
+ verify("struct a", append(S{}), S{})
+ verify("struct b", append(S{}, e[0]), e[0:1])
+ verify("struct c", append(S{}, e[0], e[1], e[2]), e[0:3])
+
+ verify("struct d", append(e[0:1]), e[0:1])
+ verify("struct e", append(e[0:1], e[1]), e[0:2])
+ verify("struct f", append(e[0:1], e[1], e[2], e[3]), e[0:4])
+
+ verify("struct g", append(e[0:3]), e[0:3])
+ verify("struct h", append(e[0:3], e[3]), e[0:4])
+ verify("struct i", append(e[0:3], e[3], e[4], e[5], e[6]), e[0:7])
+
+ for i := range e {
+ verify("struct j", append(S{}, e[0:i]...), e[0:i])
+ input := make(S, i)
+ copy(input, e[0:i])
+ verify("struct k", append(input, e[i:]...), e)
+ verify("struct k - input modified", input, e[0:i])
+ }
+
+ s := make(S, 10, 20)
+ r := make(S, len(s)+len(e))
+ for i, x := range e {
+ r[len(s)+i] = x
+ }
+ verify("struct l", append(s), s)
+ verify("struct m", append(s, e...), r)
+}
+
+
+func verifyInterface() {
+ type T interface{}
+ type S []T
+ e := make(S, 100)
+ for i := range e {
+ switch i % 4 {
+ case 0:
+ e[i] = i
+ case 1:
+ e[i] = "foo"
+ case 2:
+ e[i] = fmt.Sprintf("%d", i)
+ case 3:
+ e[i] = float(i)
+ }
+ }
+
+ verify("interface a", append(S{}), S{})
+ verify("interface b", append(S{}, e[0]), e[0:1])
+ verify("interface c", append(S{}, e[0], e[1], e[2]), e[0:3])
+
+ verify("interface d", append(e[0:1]), e[0:1])
+ verify("interface e", append(e[0:1], e[1]), e[0:2])
+ verify("interface f", append(e[0:1], e[1], e[2], e[3]), e[0:4])
+
+ verify("interface g", append(e[0:3]), e[0:3])
+ verify("interface h", append(e[0:3], e[3]), e[0:4])
+ verify("interface i", append(e[0:3], e[3], e[4], e[5], e[6]), e[0:7])
+
+ for i := range e {
+ verify("interface j", append(S{}, e[0:i]...), e[0:i])
+ input := make(S, i)
+ copy(input, e[0:i])
+ verify("interface k", append(input, e[i:]...), e)
+ verify("interface k - input modified", input, e[0:i])
+ }
+
+ s := make(S, 10, 20)
+ r := make(S, len(s)+len(e))
+ for i, x := range e {
+ r[len(s)+i] = x
+ }
+ verify("interface l", append(s), s)
+ verify("interface m", append(s, e...), r)
+}
diff --git a/test/arm-pass.txt b/test/arm-pass.txt
deleted file mode 100644
index 8878f6dc8..000000000
--- a/test/arm-pass.txt
+++ /dev/null
@@ -1,444 +0,0 @@
-./235.go
-./64bit.go # slow with GOGC=on
-./args.go
-./assign.go
-./bigalg.go
-./blank.go
-./blank1.go
-./chancap.go
-./char_lit.go
-./closedchan.go
-./closure.go
-./cmp1.go
-./cmp2.go
-./cmp3.go
-./cmp4.go
-./cmp5.go
-./complit.go
-./compos.go
-./const.go
-./const1.go
-./const2.go
-./const3.go
-./convert.go
-./convert3.go
-./convlit.go
-./convlit1.go
-# ./copy.go # slow
-./ddd.go
-./ddd1.go
-./ddd2.go
-./ddd3.go
-./decl.go
-./declbad.go
-./defer.go
-# ./deferprint.go # need floating point
-./empty.go
-./env.go
-./escape.go
-# ./float_lit.go # need floating point
-# ./floatcmp.go # need floating point
-./for.go
-# ./func.go
-./func1.go
-./func2.go
-./func3.go
-./func4.go
-./func5.go
-# ./gc.go
-# ./gc1.go
-./hashmap.go
-./hilbert.go
-./helloworld.go
-./if.go
-./if1.go
-./import.go
-./import1.go
-./import2.go
-./import3.go
-./import4.go
-./indirect.go
-./indirect1.go
-./initcomma.go
-# ./initialize.go # need floating point
-./initializerr.go
-./initsyscall.go
-./int_lit.go
-./intcvt.go
-./iota.go
-# ./literal.go # need floating point
-# ./malloc1.go
-# ./mallocfin.go
-# ./mallocrand.go
-# ./mallocrep.go
-# ./mallocrep1.go
-# ./map.go # need floating point
-./method.go
-./method1.go
-./method2.go
-./method3.go
-#./named.go # need floating point
-./named1.go
-./nil.go
-# ./nul1.go # android runner gets confused
-./parentype.go
-# ./peano.go # foo
-./printbig.go
-./range.go
-./recover.go
-./recover1.go
-./recover2.go
-./rename.go
-./rename1.go
-./runtime.go
-./sieve.go
-# ./sigchld.go # fail - does not survive signal
-./simassign.go
-./stack.go
-./string_lit.go
-./stringrange.go
-./switch.go
-./switch1.go
-./test0.go
-./turing.go
-./typeswitch.go
-# ./typeswitch1.go
-./typeswitch2.go
-./utf.go
-./varinit.go
-# ./vectors.go
-ken/array.go
-# ken/chan.go # slow
-# ken/chan1.go # slow
-ken/complit.go
-# ken/cplx0.go # need floating point
-# ken/cplx1.go # need floating point
-# ken/cplx2.go # need floating point
-# ken/cplx3.go # need floating point
-# ken/cplx4.go # need floating point
-# ken/cplx5.go # need floating point
-# ken/divconst.go # slow
-ken/divmod.go
-ken/embed.go
-ken/for.go
-ken/interbasic.go
-ken/interfun.go
-ken/intervar.go
-ken/label.go
-ken/litfun.go
-ken/mfunc.go
-# ken/modconst.go # slow
-ken/ptrfun.go
-ken/ptrvar.go
-ken/range.go
-ken/rob1.go
-ken/rob2.go
-ken/robfor.go
-# ken/robfunc.go # fail
-ken/robif.go
-ken/shift.go
-#ken/simparray.go # need floating point
-ken/simpbool.go
-#ken/simpconv.go # need floating point
-ken/simpfun.go
-ken/simpprint.go
-ken/simpswitch.go
-ken/simpvar.go
-#ken/slicearray.go # need floating point
-#ken/sliceslice.go # need floating point
-ken/string.go
-ken/strvar.go
-# chan/doubleselect.go # slow
-chan/fifo.go
-chan/goroutines.go
-chan/nonblock.go
-chan/perm.go
-chan/powser1.go
-chan/powser2.go
-chan/select.go
-chan/select2.go
-chan/sieve1.go
-chan/sieve2.go
-interface/bigdata.go
-interface/convert.go
-interface/convert1.go
-interface/convert2.go
-interface/embed.go
-interface/embed0.go
-interface/embed1.go
-interface/explicit.go
-# interface/fake.go # fails - panic: assert
-interface/fail.go
-interface/pointer.go
-interface/receiver.go
-interface/receiver1.go
-interface/recursive.go
-interface/returntype.go
-interface/struct.go
-nilptr/arrayindex.go
-nilptr/arrayindex1.go
-nilptr/arraytoslice.go
-nilptr/arraytoslice1.go
-nilptr/arraytoslice2.go
-nilptr/slicearray.go
-nilptr/structfield.go
-nilptr/structfield1.go
-nilptr/structfield2.go
-nilptr/structfieldaddr.go
-syntax/forvar.go
-syntax/import.go
-syntax/interface.go
-syntax/semi1.go
-syntax/semi2.go
-syntax/semi3.go
-syntax/semi4.go
-syntax/semi5.go
-syntax/semi6.go
-syntax/semi7.go
-syntax/slice.go
-syntax/vareq.go
-syntax/vareq1.go
-fixedbugs/bug000.go
-fixedbugs/bug001.go
-fixedbugs/bug002.go
-fixedbugs/bug003.go
-fixedbugs/bug004.go
-fixedbugs/bug005.go
-fixedbugs/bug006.go
-fixedbugs/bug007.go
-fixedbugs/bug008.go
-fixedbugs/bug009.go
-fixedbugs/bug010.go
-#fixedbugs/bug011.go # need floating point
-fixedbugs/bug012.go
-fixedbugs/bug013.go
-fixedbugs/bug014.go
-fixedbugs/bug015.go
-fixedbugs/bug016.go
-fixedbugs/bug017.go
-fixedbugs/bug020.go
-fixedbugs/bug021.go
-fixedbugs/bug022.go
-fixedbugs/bug023.go
-fixedbugs/bug024.go
-fixedbugs/bug026.go
-fixedbugs/bug027.go
-fixedbugs/bug028.go
-fixedbugs/bug030.go
-fixedbugs/bug031.go
-fixedbugs/bug035.go
-fixedbugs/bug036.go
-fixedbugs/bug037.go
-fixedbugs/bug038.go
-fixedbugs/bug039.go
-fixedbugs/bug040.go
-fixedbugs/bug045.go
-fixedbugs/bug046.go
-fixedbugs/bug047.go
-fixedbugs/bug048.go
-fixedbugs/bug049.go
-fixedbugs/bug050.go
-fixedbugs/bug051.go
-fixedbugs/bug052.go
-fixedbugs/bug053.go
-fixedbugs/bug054.go
-fixedbugs/bug055.go
-fixedbugs/bug056.go
-fixedbugs/bug057.go
-fixedbugs/bug058.go
-fixedbugs/bug059.go
-fixedbugs/bug060.go
-fixedbugs/bug061.go
-fixedbugs/bug062.go
-fixedbugs/bug063.go
-fixedbugs/bug064.go
-fixedbugs/bug065.go
-fixedbugs/bug066.go
-fixedbugs/bug067.go
-fixedbugs/bug068.go
-fixedbugs/bug069.go
-fixedbugs/bug070.go
-fixedbugs/bug071.go
-fixedbugs/bug072.go
-fixedbugs/bug073.go
-fixedbugs/bug074.go
-fixedbugs/bug075.go
-fixedbugs/bug076.go
-fixedbugs/bug077.go
-fixedbugs/bug078.go
-fixedbugs/bug080.go
-fixedbugs/bug081.go
-fixedbugs/bug082.go
-fixedbugs/bug083.go
-fixedbugs/bug084.go
-fixedbugs/bug085.go
-fixedbugs/bug086.go
-fixedbugs/bug087.go
-fixedbugs/bug088.go
-fixedbugs/bug089.go
-fixedbugs/bug090.go
-fixedbugs/bug091.go
-fixedbugs/bug092.go
-fixedbugs/bug093.go
-fixedbugs/bug094.go
-fixedbugs/bug096.go
-fixedbugs/bug097.go
-fixedbugs/bug098.go
-fixedbugs/bug099.go
-fixedbugs/bug101.go
-fixedbugs/bug102.go
-fixedbugs/bug103.go
-fixedbugs/bug104.go
-fixedbugs/bug106.go
-fixedbugs/bug107.go
-fixedbugs/bug108.go
-fixedbugs/bug109.go
-fixedbugs/bug110.go
-fixedbugs/bug111.go
-fixedbugs/bug112.go
-fixedbugs/bug113.go
-fixedbugs/bug114.go
-fixedbugs/bug115.go
-fixedbugs/bug116.go
-fixedbugs/bug117.go
-fixedbugs/bug118.go
-fixedbugs/bug119.go
-# fixedbugs/bug120.go # needs floating point
-fixedbugs/bug121.go
-fixedbugs/bug122.go
-fixedbugs/bug123.go
-fixedbugs/bug126.go
-fixedbugs/bug127.go
-fixedbugs/bug128.go
-fixedbugs/bug129.go
-fixedbugs/bug130.go
-fixedbugs/bug131.go
-fixedbugs/bug132.go
-fixedbugs/bug133.go
-fixedbugs/bug135.go
-fixedbugs/bug136.go
-fixedbugs/bug137.go
-fixedbugs/bug139.go
-fixedbugs/bug140.go
-fixedbugs/bug141.go
-fixedbugs/bug142.go
-fixedbugs/bug143.go
-fixedbugs/bug144.go
-fixedbugs/bug145.go
-fixedbugs/bug146.go
-fixedbugs/bug147.go
-fixedbugs/bug148.go
-fixedbugs/bug149.go
-fixedbugs/bug150.go
-fixedbugs/bug151.go
-fixedbugs/bug152.go
-fixedbugs/bug153.go
-# fixedbugs/bug154.go # needs floating point
-fixedbugs/bug155.go
-fixedbugs/bug156.go
-fixedbugs/bug157.go
-fixedbugs/bug158.go
-fixedbugs/bug159.go
-fixedbugs/bug160.go
-fixedbugs/bug161.go
-fixedbugs/bug163.go
-fixedbugs/bug164.go
-fixedbugs/bug165.go
-fixedbugs/bug167.go
-fixedbugs/bug168.go
-fixedbugs/bug169.go
-fixedbugs/bug170.go
-fixedbugs/bug171.go
-fixedbugs/bug172.go
-fixedbugs/bug173.go
-fixedbugs/bug174.go
-fixedbugs/bug175.go
-fixedbugs/bug176.go
-fixedbugs/bug177.go
-fixedbugs/bug178.go
-fixedbugs/bug179.go
-fixedbugs/bug180.go
-fixedbugs/bug181.go
-fixedbugs/bug182.go
-fixedbugs/bug183.go
-fixedbugs/bug184.go
-fixedbugs/bug185.go
-fixedbugs/bug186.go
-fixedbugs/bug187.go
-fixedbugs/bug188.go
-fixedbugs/bug189.go
-fixedbugs/bug190.go
-fixedbugs/bug191.go
-fixedbugs/bug192.go
-fixedbugs/bug193.go
-fixedbugs/bug194.go
-fixedbugs/bug195.go
-fixedbugs/bug196.go
-fixedbugs/bug197.go
-fixedbugs/bug198.go
-fixedbugs/bug199.go
-fixedbugs/bug200.go
-fixedbugs/bug201.go
-fixedbugs/bug202.go
-fixedbugs/bug203.go
-fixedbugs/bug204.go
-fixedbugs/bug205.go
-fixedbugs/bug206.go
-fixedbugs/bug207.go
-fixedbugs/bug208.go
-fixedbugs/bug209.go
-fixedbugs/bug211.go
-fixedbugs/bug212.go
-fixedbugs/bug213.go
-fixedbugs/bug214.go
-fixedbugs/bug215.go
-fixedbugs/bug216.go
-fixedbugs/bug217.go
-fixedbugs/bug218.go
-fixedbugs/bug219.go
-fixedbugs/bug220.go
-# fixedbugs/bug221.go # slow
-fixedbugs/bug222.go
-fixedbugs/bug223.go
-fixedbugs/bug224.go
-fixedbugs/bug225.go
-fixedbugs/bug226.go
-fixedbugs/bug227.go
-fixedbugs/bug228.go
-fixedbugs/bug229.go
-fixedbugs/bug230.go
-fixedbugs/bug231.go
-fixedbugs/bug232.go
-fixedbugs/bug233.go
-fixedbugs/bug234.go
-fixedbugs/bug235.go
-# fixedbugs/bug236.go # slow
-fixedbugs/bug237.go
-fixedbugs/bug238.go
-fixedbugs/bug239.go
-fixedbugs/bug240.go
-fixedbugs/bug241.go
-fixedbugs/bug242.go
-# fixedbugs/bug243.go # fail
-fixedbugs/bug244.go
-fixedbugs/bug245.go
-fixedbugs/bug246.go
-fixedbugs/bug247.go
-fixedbugs/bug248.go
-fixedbugs/bug249.go
-fixedbugs/bug250.go
-fixedbugs/bug251.go
-fixedbugs/bug252.go
-fixedbugs/bug253.go
-fixedbugs/bug254.go
-fixedbugs/bug255.go
-fixedbugs/bug256.go
-# fixedbugs/bug257.go # slow
-# fixedbugs/bug258.go # needs floating point
-fixedbugs/bug259.go
-fixedbugs/bug261.go
-fixedbugs/bug262.go
-fixedbugs/bug263.go
-fixedbugs/bug264.go
-fixedbugs/bug265.go
-bugs/bug260.go
diff --git a/test/assign.go b/test/assign.go
index fea7c2828..59471388c 100644
--- a/test/assign.go
+++ b/test/assign.go
@@ -9,45 +9,45 @@ package main
import "sync"
type T struct {
- int;
- sync.Mutex;
+ int
+ sync.Mutex
}
func main() {
{
- var x, y sync.Mutex;
- x = y; // ERROR "assignment.*Mutex"
- _ = x;
+ var x, y sync.Mutex
+ x = y // ERROR "assignment.*Mutex"
+ _ = x
}
{
- var x, y T;
- x = y; // ERROR "assignment.*Mutex"
- _ = x;
+ var x, y T
+ x = y // ERROR "assignment.*Mutex"
+ _ = x
}
{
- var x, y [2]sync.Mutex;
- x = y; // ERROR "assignment.*Mutex"
- _ = x;
+ var x, y [2]sync.Mutex
+ x = y // ERROR "assignment.*Mutex"
+ _ = x
}
{
- var x, y [2]T;
- x = y; // ERROR "assignment.*Mutex"
- _ = x;
+ var x, y [2]T
+ x = y // ERROR "assignment.*Mutex"
+ _ = x
}
{
- x := sync.Mutex{0, 0}; // ERROR "assignment.*Mutex"
- _ = x;
+ x := sync.Mutex{0, 0} // ERROR "assignment.*Mutex"
+ _ = x
}
{
- x := sync.Mutex{key: 0}; // ERROR "(unknown|assignment).*Mutex"
- _ = x;
+ x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex"
+ _ = x
}
{
- x := &sync.Mutex{}; // ok
- var y sync.Mutex; // ok
- y = *x; // ERROR "assignment.*Mutex"
- *x = y; // ERROR "assignment.*Mutex"
- _ = x;
- _ = y;
+ x := &sync.Mutex{} // ok
+ var y sync.Mutex // ok
+ y = *x // ERROR "assignment.*Mutex"
+ *x = y // ERROR "assignment.*Mutex"
+ _ = x
+ _ = y
}
}
diff --git a/test/assign1.go b/test/assign1.go
index 452f90f1c..71e5b4064 100644
--- a/test/assign1.go
+++ b/test/assign1.go
@@ -155,61 +155,61 @@ func main() {
s1 = s0
s1 = s // ERROR "cannot use"
- pa0 = pa // ERROR "cannot use"
- pa0 = pa1 // ERROR "cannot use"
- pa = pa0 // ERROR "cannot use"
- pa = pa1 // ERROR "cannot use"
- pa1 = pa0 // ERROR "cannot use"
- pa1 = pa // ERROR "cannot use"
-
- pb0 = pb // ERROR "cannot use"
- pb0 = pb1 // ERROR "cannot use"
- pb = pb0 // ERROR "cannot use"
- pb = pb1 // ERROR "cannot use"
- pb1 = pb0 // ERROR "cannot use"
- pb1 = pb // ERROR "cannot use"
-
- pc0 = pc // ERROR "cannot use"
- pc0 = pc1 // ERROR "cannot use"
- pc = pc0 // ERROR "cannot use"
- pc = pc1 // ERROR "cannot use"
- pc1 = pc0 // ERROR "cannot use"
- pc1 = pc // ERROR "cannot use"
-
- pf0 = pf // ERROR "cannot use"
- pf0 = pf1 // ERROR "cannot use"
- pf = pf0 // ERROR "cannot use"
- pf = pf1 // ERROR "cannot use"
- pf1 = pf0 // ERROR "cannot use"
- pf1 = pf // ERROR "cannot use"
-
- pi0 = pi // ERROR "cannot use"
- pi0 = pi1 // ERROR "cannot use"
- pi = pi0 // ERROR "cannot use"
- pi = pi1 // ERROR "cannot use"
- pi1 = pi0 // ERROR "cannot use"
- pi1 = pi // ERROR "cannot use"
-
- pm0 = pm // ERROR "cannot use"
- pm0 = pm1 // ERROR "cannot use"
- pm = pm0 // ERROR "cannot use"
- pm = pm1 // ERROR "cannot use"
- pm1 = pm0 // ERROR "cannot use"
- pm1 = pm // ERROR "cannot use"
-
- pp0 = pp // ERROR "cannot use"
- pp0 = pp1 // ERROR "cannot use"
- pp = pp0 // ERROR "cannot use"
- pp = pp1 // ERROR "cannot use"
- pp1 = pp0 // ERROR "cannot use"
- pp1 = pp // ERROR "cannot use"
-
- ps0 = ps // ERROR "cannot use"
- ps0 = ps1 // ERROR "cannot use"
- ps = ps0 // ERROR "cannot use"
- ps = ps1 // ERROR "cannot use"
- ps1 = ps0 // ERROR "cannot use"
- ps1 = ps // ERROR "cannot use"
+ pa0 = pa // ERROR "cannot use|incompatible"
+ pa0 = pa1 // ERROR "cannot use|incompatible"
+ pa = pa0 // ERROR "cannot use|incompatible"
+ pa = pa1 // ERROR "cannot use|incompatible"
+ pa1 = pa0 // ERROR "cannot use|incompatible"
+ pa1 = pa // ERROR "cannot use|incompatible"
+
+ pb0 = pb // ERROR "cannot use|incompatible"
+ pb0 = pb1 // ERROR "cannot use|incompatible"
+ pb = pb0 // ERROR "cannot use|incompatible"
+ pb = pb1 // ERROR "cannot use|incompatible"
+ pb1 = pb0 // ERROR "cannot use|incompatible"
+ pb1 = pb // ERROR "cannot use|incompatible"
+
+ pc0 = pc // ERROR "cannot use|incompatible"
+ pc0 = pc1 // ERROR "cannot use|incompatible"
+ pc = pc0 // ERROR "cannot use|incompatible"
+ pc = pc1 // ERROR "cannot use|incompatible"
+ pc1 = pc0 // ERROR "cannot use|incompatible"
+ pc1 = pc // ERROR "cannot use|incompatible"
+
+ pf0 = pf // ERROR "cannot use|incompatible"
+ pf0 = pf1 // ERROR "cannot use|incompatible"
+ pf = pf0 // ERROR "cannot use|incompatible"
+ pf = pf1 // ERROR "cannot use|incompatible"
+ pf1 = pf0 // ERROR "cannot use|incompatible"
+ pf1 = pf // ERROR "cannot use|incompatible"
+
+ pi0 = pi // ERROR "cannot use|incompatible"
+ pi0 = pi1 // ERROR "cannot use|incompatible"
+ pi = pi0 // ERROR "cannot use|incompatible"
+ pi = pi1 // ERROR "cannot use|incompatible"
+ pi1 = pi0 // ERROR "cannot use|incompatible"
+ pi1 = pi // ERROR "cannot use|incompatible"
+
+ pm0 = pm // ERROR "cannot use|incompatible"
+ pm0 = pm1 // ERROR "cannot use|incompatible"
+ pm = pm0 // ERROR "cannot use|incompatible"
+ pm = pm1 // ERROR "cannot use|incompatible"
+ pm1 = pm0 // ERROR "cannot use|incompatible"
+ pm1 = pm // ERROR "cannot use|incompatible"
+
+ pp0 = pp // ERROR "cannot use|incompatible"
+ pp0 = pp1 // ERROR "cannot use|incompatible"
+ pp = pp0 // ERROR "cannot use|incompatible"
+ pp = pp1 // ERROR "cannot use|incompatible"
+ pp1 = pp0 // ERROR "cannot use|incompatible"
+ pp1 = pp // ERROR "cannot use|incompatible"
+
+ ps0 = ps // ERROR "cannot use|incompatible"
+ ps0 = ps1 // ERROR "cannot use|incompatible"
+ ps = ps0 // ERROR "cannot use|incompatible"
+ ps = ps1 // ERROR "cannot use|incompatible"
+ ps1 = ps0 // ERROR "cannot use|incompatible"
+ ps1 = ps // ERROR "cannot use|incompatible"
a0 = [10]int(a)
diff --git a/test/bench/fannkuch-parallel.go b/test/bench/fannkuch-parallel.go
index 7897eac05..7e9b98d50 100644
--- a/test/bench/fannkuch-parallel.go
+++ b/test/bench/fannkuch-parallel.go
@@ -44,7 +44,7 @@ import (
)
var n = flag.Int("n", 7, "count")
-var nCPU = flag.Int("ncpu", 2, "number of cpus")
+var nCPU = flag.Int("ncpu", 4, "number of cpus")
type Job struct {
start []int
diff --git a/test/bench/fasta.c b/test/bench/fasta.c
index 78a8490d7..64c1c5205 100644
--- a/test/bench/fasta.c
+++ b/test/bench/fasta.c
@@ -41,10 +41,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include <string.h>
+#ifndef fwrite_unlocked
// not available on OS X
#define fwrite_unlocked fwrite
#define fputc_unlocked fputc
#define fputs_unlocked fputs
+#endif
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#define unlikely(x) __builtin_expect((x), 0)
@@ -214,4 +216,4 @@ main(int argc, const char **argv) {
">THREE Homo sapiens frequency\n", n*5, &rand);
return 0;
-} \ No newline at end of file
+}
diff --git a/test/bench/fasta.go b/test/bench/fasta.go
index 470bdb328..d13edd5dc 100644
--- a/test/bench/fasta.go
+++ b/test/bench/fasta.go
@@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
package main
import (
- "bytes"
"flag"
"os"
)
@@ -49,7 +48,7 @@ var n = flag.Int("n", 1000, "length of result")
const Line = 60
func Repeat(alu []byte, n int) {
- buf := bytes.Add(alu, alu)
+ buf := append(alu, alu...)
off := 0
for n > 0 {
m := n
@@ -138,28 +137,28 @@ func main() {
flag.Parse()
iub := []Acid{
- Acid{prob: 0.27, sym: 'a'},
- Acid{prob: 0.12, sym: 'c'},
- Acid{prob: 0.12, sym: 'g'},
- Acid{prob: 0.27, sym: 't'},
- Acid{prob: 0.02, sym: 'B'},
- Acid{prob: 0.02, sym: 'D'},
- Acid{prob: 0.02, sym: 'H'},
- Acid{prob: 0.02, sym: 'K'},
- Acid{prob: 0.02, sym: 'M'},
- Acid{prob: 0.02, sym: 'N'},
- Acid{prob: 0.02, sym: 'R'},
- Acid{prob: 0.02, sym: 'S'},
- Acid{prob: 0.02, sym: 'V'},
- Acid{prob: 0.02, sym: 'W'},
- Acid{prob: 0.02, sym: 'Y'},
+ {prob: 0.27, sym: 'a'},
+ {prob: 0.12, sym: 'c'},
+ {prob: 0.12, sym: 'g'},
+ {prob: 0.27, sym: 't'},
+ {prob: 0.02, sym: 'B'},
+ {prob: 0.02, sym: 'D'},
+ {prob: 0.02, sym: 'H'},
+ {prob: 0.02, sym: 'K'},
+ {prob: 0.02, sym: 'M'},
+ {prob: 0.02, sym: 'N'},
+ {prob: 0.02, sym: 'R'},
+ {prob: 0.02, sym: 'S'},
+ {prob: 0.02, sym: 'V'},
+ {prob: 0.02, sym: 'W'},
+ {prob: 0.02, sym: 'Y'},
}
homosapiens := []Acid{
- Acid{prob: 0.3029549426680, sym: 'a'},
- Acid{prob: 0.1979883004921, sym: 'c'},
- Acid{prob: 0.1975473066391, sym: 'g'},
- Acid{prob: 0.3015094502008, sym: 't'},
+ {prob: 0.3029549426680, sym: 'a'},
+ {prob: 0.1979883004921, sym: 'c'},
+ {prob: 0.1975473066391, sym: 'g'},
+ {prob: 0.3015094502008, sym: 't'},
}
alu := []byte(
@@ -192,9 +191,7 @@ func (b *buffer) Flush() {
func (b *buffer) WriteString(s string) {
p := b.NextWrite(len(s))
- for i := 0; i < len(s); i++ {
- p[i] = s[i]
- }
+ copy(p, s)
}
func (b *buffer) NextWrite(n int) []byte {
@@ -204,6 +201,6 @@ func (b *buffer) NextWrite(n int) []byte {
p = *b
}
out := p[len(p) : len(p)+n]
- *b = p[0 : len(p)+n]
+ *b = p[:len(p)+n]
return out
}
diff --git a/test/bench/k-nucleotide-parallel.go b/test/bench/k-nucleotide-parallel.go
index 0234f33d1..96c80d8f0 100644
--- a/test/bench/k-nucleotide-parallel.go
+++ b/test/bench/k-nucleotide-parallel.go
@@ -41,6 +41,7 @@ import (
"fmt"
"io/ioutil"
"os"
+ "runtime"
"sort"
)
@@ -97,6 +98,7 @@ func printKnucs(a kNucArray) {
}
func main() {
+ runtime.GOMAXPROCS(4)
in := bufio.NewReader(os.Stdin)
three := []byte(">THREE ")
for {
diff --git a/test/bench/pidigits.go b/test/bench/pidigits.go
index dcfb502ce..e59312177 100644
--- a/test/bench/pidigits.go
+++ b/test/bench/pidigits.go
@@ -49,6 +49,7 @@ var silent = flag.Bool("s", false, "don't print result")
var (
tmp1 = big.NewInt(0)
tmp2 = big.NewInt(0)
+ tmp3 = big.NewInt(0)
y2 = big.NewInt(0)
bigk = big.NewInt(0)
numer = big.NewInt(1)
@@ -80,7 +81,6 @@ func extract_digit() int64 {
}
func next_term(k int64) {
- // TODO(eds) If big.Int ever gets a Scale method, y2 and bigk could be int64
y2.SetInt64(k*2 + 1)
bigk.SetInt64(k)
@@ -92,15 +92,15 @@ func next_term(k int64) {
}
func eliminate_digit(d int64) {
- tmp := big.NewInt(0).Set(denom)
- accum.Sub(accum, tmp.Mul(tmp, big.NewInt(d)))
+ tmp3.SetInt64(d)
+ accum.Sub(accum, tmp3.Mul(denom, tmp3))
accum.Mul(accum, ten)
numer.Mul(numer, ten)
}
func printf(s string, arg ...interface{}) {
if !*silent {
- fmt.Printf(s, arg)
+ fmt.Printf(s, arg...)
}
}
diff --git a/test/bench/regex-dna-parallel.go b/test/bench/regex-dna-parallel.go
index d33f2466e..e8e62b806 100644
--- a/test/bench/regex-dna-parallel.go
+++ b/test/bench/regex-dna-parallel.go
@@ -77,8 +77,8 @@ func countMatches(pat string, bytes []byte) int {
re := regexp.MustCompile(pat)
n := 0
for {
- e := re.Execute(bytes)
- if len(e) == 0 {
+ e := re.FindIndex(bytes)
+ if e == nil {
break
}
n++
diff --git a/test/bench/regex-dna.go b/test/bench/regex-dna.go
index 22de2c6aa..dc31db768 100644
--- a/test/bench/regex-dna.go
+++ b/test/bench/regex-dna.go
@@ -76,7 +76,7 @@ func countMatches(pat string, bytes []byte) int {
re := regexp.MustCompile(pat)
n := 0
for {
- e := re.Execute(bytes)
+ e := re.FindIndex(bytes)
if len(e) == 0 {
break
}
diff --git a/test/bench/timing.log b/test/bench/timing.log
index e7b0b48c1..f2b6a1f40 100644
--- a/test/bench/timing.log
+++ b/test/bench/timing.log
@@ -90,7 +90,7 @@ mandelbrot 5500
gc mandelbrot 74.32u 0.00s 74.35r
gc_B mandelbrot 74.28u 0.01s 74.31r
-meteor 16000
+meteor 2100
# we don't know
gcc -O2 meteor-contest.c 0.10u 0.00s 0.10r
gccgo -O2 meteor-contest.go 0.12u 0.00s 0.14r
@@ -209,7 +209,7 @@ mandelbrot 16000
gc mandelbrot 64.05u 0.02s 64.08r # *** -14%
gc_B mandelbrot 64.10u 0.02s 64.14r # *** -14%
-meteor 16000
+meteor 2100
# we don't know
gcc -O2 meteor-contest.c 0.10u 0.00s 0.10r
gccgo -O2 meteor-contest.go 0.12u 0.00s 0.12r
@@ -307,7 +307,7 @@ mandelbrot 16000
gc mandelbrot 63.31u 0.01s 63.35r # -1%
gc_B mandelbrot 63.29u 0.00s 63.31r # -1%
-meteor 16000
+meteor 2100
# we don't know
gcc -O2 meteor-contest.c 0.10u 0.00s 0.10r
gccgo -O2 meteor-contest.go 0.11u 0.00s 0.12r
@@ -414,7 +414,7 @@ chameneos 6000000
gcc -O2 chameneosredux.c -lpthread 18.00u 303.29s 83.64r
gc chameneosredux 12.10u 0.00s 12.10r # 2.22X faster
-Jan 6, 2009
+Jan 6, 2010
# Long-overdue update. All numbers included in this complete run.
# Some programs (e.g. reverse-complement) rewritten for speed.
@@ -429,7 +429,7 @@ fasta -n 25000000
reverse-complement < output-of-fasta-25000000
gcc -O2 reverse-complement.c 2.00u 0.80s 9.54r
- gccgo -O2 reverse-complement.go 4.57u 0.35s 4.94r # 33% faster
+# gccgo -O2 reverse-complement.go 4.57u 0.35s 4.94r # 33% faster
gc reverse-complement 2.01u 0.38s 2.40r # 3.3X faster
gc_B reverse-complement 1.88u 0.36s 2.24r # 3.2X faster
GOGC=off
@@ -445,7 +445,6 @@ nbody -n 50000000
binary-tree 15 # too slow to use 20
gcc -O2 binary-tree.c -lm 0.86u 0.00s 0.87r
gccgo -O2 binary-tree.go 4.82u 0.41s 5.24r # 2.5X slower
- gccgo -O2 binary-tree-freelist.go 0.00u 0.00s 0.00r
gc binary-tree 7.23u 0.01s 7.25r # # -19%
gc binary-tree-freelist 0.43u 0.00s 0.44r # -9%
@@ -478,7 +477,7 @@ mandelbrot 16000
gc mandelbrot 66.05u 0.00s 66.07r # -3%
gc_B mandelbrot 66.06u 0.00s 66.07r # -3%
-meteor 16000
+meteor 2100
gcc -O2 meteor-contest.c 0.10u 0.00s 0.10r
gccgo -O2 meteor-contest.go 0.12u 0.00s 0.12r
gc meteor-contest 0.17u 0.00s 0.17r
@@ -498,3 +497,98 @@ chameneos 6000000
gcc -O2 chameneosredux.c -lpthread 19.02u 331.08s 90.79r
gc chameneosredux 12.54u 0.00s 12.55r
+Oct 19, 2010
+
+# Another long-overdue update. Some of the code is new; parallel versions
+# of some are added. A few significant improvements.
+
+fasta -n 25000000
+ gcc -O2 fasta.c 4.92u 0.00s 4.93r
+ gccgo -O2 fasta.go 3.31u 0.00s 3.34r # new code
+ gc fasta 3.68u 0.00s 3.69r # 2.5X faster with no code
+ gc_B fasta 3.68u 0.00s 3.69r # 2.3X faster with no code
+
+reverse-complement < output-of-fasta-25000000
+ gcc -O2 reverse-complement.c 1.93u 0.81s 11.24r
+ gccgo -O2 reverse-complement.go 1.58u 0.43s 2.04r # first run with new code?
+ gc reverse-complement 1.84u 0.34s 2.20r # 10% faster
+ gc_B reverse-complement 1.85u 0.32s 2.18r
+
+nbody -n 50000000
+ gcc -O2 nbody.c 21.35u 0.00s 21.36r
+ gccgo -O2 nbody.go 21.62u 0.00s 21.66r # 3.7X faster - why??
+ gc nbody 29.78u 0.00s 29.79r
+ gc_B nbody 29.72u 0.00s 29.72r
+
+binary-tree 15 # too slow to use 20
+ gcc -O2 binary-tree.c -lm 0.86u 0.00s 0.88r
+ gccgo -O2 binary-tree.go 4.05u 0.02s 4.08r # 28% faster
+ gccgo -O2 binary-tree-freelist 0.34u 0.08s 0.34r
+ gc binary-tree 5.94u 0.00s 5.95r # 20% faster
+ gc binary-tree-freelist 0.50u 0.01s 0.54r
+
+fannkuch 12
+ gcc -O2 fannkuch.c 60.45u 0.00s 60.45r
+ gccgo -O2 fannkuch.go 64.64u 0.00s 64.64r
+ gccgo -O2 fannkuch-parallel.go 115.63u 0.00s 31.58r
+ gc fannkuch 126.52u 0.04s 126.68r
+ gc fannkuch-parallel 238.82u 0.10s 65.93r # GOMAXPROCS=4
+ gc_B fannkuch 88.99u 0.00s 89.02r
+
+regex-dna 100000
+ gcc -O2 regex-dna.c -lpcre 0.89u 0.00s 0.89r
+ gc regex-dna 8.99u 0.02s 9.03r
+ gc regex-dna-parallel 8.94u 0.02s 3.68r # GOMAXPROCS=4
+ gc_B regex-dna 9.12u 0.00s 9.14r
+
+spectral-norm 5500
+ gcc -O2 spectral-norm.c -lm 11.55u 0.00s 11.57r
+ gccgo -O2 spectral-norm.go 11.73u 0.00s 11.75r
+ gc spectral-norm 23.74u 0.00s 23.79r
+ gc_B spectral-norm 24.49u 0.02s 24.54r
+
+k-nucleotide 1000000
+ gcc -O2 k-nucleotide.c 11.44u 0.06s 11.50r
+ gccgo -O2 k-nucleotide.go 8.65u 0.04s 8.71r
+ gccgo -O2 k-nucleotide-parallel.go 8.75u 0.03s 2.97r # set GOMAXPROCS=4
+ gc k-nucleotide 14.92u 0.05s 15.01r
+ gc k-nucleotide-parallel 16.96u 0.06s 6.53r # set GOMAXPROCS=4
+ gc_B k-nucleotide 15.97u 0.03s 16.08r
+
+mandelbrot 16000
+ gcc -O2 mandelbrot.c 56.32u 0.00s 56.35r
+ gccgo -O2 mandelbrot.go 55.62u 0.02s 55.77r
+ gc mandelbrot 64.85u 0.01s 64.94r
+ gc_B mandelbrot 65.02u 0.01s 65.14r
+
+meteor 2100
+ gcc -O2 meteor-contest.c 0.10u 0.00s 0.10r
+ gccgo -O2 meteor-contest.go 0.10u 0.00s 0.11r
+ gc meteor-contest 0.17u 0.00s 0.18r
+ gc_B meteor-contest 0.16u 0.00s 0.16r
+
+pidigits 10000
+ gcc -O2 pidigits.c -lgmp 2.58u 0.00s 2.59r
+ gccgo -O2 pidigits.go 14.06u 0.01s 14.09r # first run?
+ gc pidigits 8.47u 0.05s 8.55r # 4.5X faster due to package big
+ gc_B pidigits 8.33u 0.01s 8.36r # 4.5X faster due to package big
+
+threadring 50000000
+ gcc -O2 threadring.c 28.18u 153.19s 186.47r
+ gccgo -O2 threadring.go 110.10u 516.48s 515.25r
+ gc threadring 40.39u 0.00s 40.40r
+
+chameneos 6000000
+ gcc -O2 chameneosredux.c -lpthread 18.20u 301.55s 83.10r
+ gccgo -O2 chameneosredux.go 52.22u 324.54s 201.21r
+ gc chameneosredux 13.52u 0.00s 13.54r
+
+Dec 14, 2010
+
+# Improved regex code (same algorithm) gets ~30%.
+
+regex-dna 100000
+ gcc -O2 regex-dna.c -lpcre 0.77u 0.01s 0.78r
+ gc regex-dna 6.80u 0.00s 6.81r
+ gc regex-dna-parallel 6.82u 0.01s 2.75r
+ gc_B regex-dna 6.69u 0.02s 6.70r
diff --git a/test/bench/timing.sh b/test/bench/timing.sh
index 5cd82dfd9..fec39182c 100755
--- a/test/bench/timing.sh
+++ b/test/bench/timing.sh
@@ -5,11 +5,15 @@
set -e
-GOBIN="${GOBIN:-$HOME/bin}"
-
-. "$GOROOT"/src/Make.$GOARCH
+eval $(gomake --no-print-directory -f ../../src/Make.inc go-env)
PATH=.:$PATH
+havegccgo=false
+if which gccgo >/dev/null 2>&1
+then
+ havegccgo=true
+fi
+
mode=run
case X"$1" in
X-test)
@@ -18,11 +22,11 @@ X-test)
esac
gc() {
- "$GOBIN"/$GC $1.go; "$GOBIN"/$LD $1.$O
+ $GC $1.go; $LD $1.$O
}
gc_B() {
- "$GOBIN"/$GC -B $1.go; "$GOBIN"/$LD $1.$O
+ $GC -B $1.go; $LD $1.$O
}
runonly() {
@@ -32,8 +36,6 @@ runonly() {
fi
}
-
-
run() {
if [ $mode = test ]
then
@@ -59,6 +61,10 @@ run() {
fi
return
fi
+ if ! $havegccgo && echo $1 | grep -q '^gccgo '
+ then
+ return
+ fi
echo -n ' '$1' '
$1
shift
@@ -69,7 +75,7 @@ run() {
fasta() {
runonly echo 'fasta -n 25000000'
run 'gcc -O2 fasta.c' a.out 25000000
- #run 'gccgo -O2 fasta.go' a.out -n 25000000 #commented out until WriteString is in bufio
+ run 'gccgo -O2 fasta.go' a.out -n 25000000 #commented out until WriteString is in bufio
run 'gc fasta' $O.out -n 25000000
run 'gc_B fasta' $O.out -n 25000000
}
@@ -87,7 +93,7 @@ revcomp() {
nbody() {
runonly echo 'nbody -n 50000000'
- run 'gcc -O2 nbody.c' a.out 50000000
+ run 'gcc -O2 -lm nbody.c' a.out 50000000
run 'gccgo -O2 nbody.go' a.out -n 50000000
run 'gc nbody' $O.out -n 50000000
run 'gc_B nbody' $O.out -n 50000000
@@ -117,7 +123,7 @@ regexdna() {
runonly a.out 100000 > x
runonly echo 'regex-dna 100000'
run 'gcc -O2 regex-dna.c -lpcre' a.out <x
-# run 'gccgo -O2 regex-dna.go' a.out <x # pages badly; don't run
+# run 'gccgo -O2 regex-dna.go' a.out <x # restore after regexp.FindIndex is in library
run 'gc regex-dna' $O.out <x
run 'gc regex-dna-parallel' $O.out <x
run 'gc_B regex-dna' $O.out <x
@@ -137,8 +143,8 @@ knucleotide() {
runonly a.out 1000000 > x # should be using 25000000
runonly echo 'k-nucleotide 1000000'
run 'gcc -O2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include k-nucleotide.c -lglib-2.0' a.out <x
- run 'gccgo -O2 k-nucleotide.go' a.out <x # warning: pages badly!
- run 'gccgo -O2 k-nucleotide-parallel.go' a.out <x # warning: pages badly!
+ run 'gccgo -O2 k-nucleotide.go' a.out <x
+ run 'gccgo -O2 k-nucleotide-parallel.go' a.out <x
run 'gc k-nucleotide' $O.out <x
run 'gc k-nucleotide-parallel' $O.out <x
run 'gc_B k-nucleotide' $O.out <x
@@ -154,17 +160,17 @@ mandelbrot() {
}
meteor() {
- runonly echo 'meteor 16000'
- run 'gcc -O2 meteor-contest.c' a.out
- run 'gccgo -O2 meteor-contest.go' a.out
- run 'gc meteor-contest' $O.out
- run 'gc_B meteor-contest' $O.out
+ runonly echo 'meteor 2098'
+ run 'gcc -O2 meteor-contest.c' a.out 2098
+ run 'gccgo -O2 meteor-contest.go' a.out -n 2098
+ run 'gc meteor-contest' $O.out -n 2098
+ run 'gc_B meteor-contest' $O.out -n 2098
}
pidigits() {
runonly echo 'pidigits 10000'
run 'gcc -O2 pidigits.c -lgmp' a.out 10000
-# run 'gccgo -O2 pidigits.go' a.out -n 10000 # uncomment when gccgo library updated
+ run 'gccgo -O2 pidigits.go' a.out -n 10000
run 'gc pidigits' $O.out -n 10000
run 'gc_B pidigits' $O.out -n 10000
}
diff --git a/test/bigalg.go b/test/bigalg.go
index 31ce222d6..902ba8410 100644
--- a/test/bigalg.go
+++ b/test/bigalg.go
@@ -7,35 +7,35 @@
package main
type T struct {
- a float64;
- b int64;
- c string;
- d byte;
+ a float64
+ b int64
+ c string
+ d byte
}
var a = []int{ 1, 2, 3 }
-var NIL []int;
+var NIL []int
func arraycmptest() {
if NIL != nil {
- println("fail1:", NIL, "!= nil");
+ println("fail1:", NIL, "!= nil")
}
if nil != NIL {
- println("fail2: nil !=", NIL);
+ println("fail2: nil !=", NIL)
}
if a == nil || nil == a {
- println("fail3:", a, "== nil");
+ println("fail3:", a, "== nil")
}
}
func SameArray(a, b []int) bool {
if len(a) != len(b) || cap(a) != cap(b) {
- return false;
+ return false
}
if len(a) > 0 && &a[0] != &b[0] {
- return false;
+ return false
}
- return true;
+ return true
}
var t = T{1.5, 123, "hello", 255}
@@ -43,16 +43,16 @@ var mt = make(map[int]T)
var ma = make(map[int][]int)
func maptest() {
- mt[0] = t;
- t1 := mt[0];
+ mt[0] = t
+ t1 := mt[0]
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
- println("fail: map val struct", t1.a, t1.b, t1.c, t1.d);
+ println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
}
- ma[1] = a;
- a1 := ma[1];
+ ma[1] = a
+ a1 := ma[1]
if !SameArray(a, a1) {
- println("fail: map val array", a, a1);
+ println("fail: map val array", a, a1)
}
}
@@ -60,21 +60,21 @@ var ct = make(chan T)
var ca = make(chan []int)
func send() {
- ct <- t;
- ca <- a;
+ ct <- t
+ ca <- a
}
func chantest() {
- go send();
+ go send()
- t1 := <-ct;
+ t1 := <-ct
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
- println("fail: map val struct", t1.a, t1.b, t1.c, t1.d);
+ println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
}
- a1 := <-ca;
+ a1 := <-ca
if !SameArray(a, a1) {
- println("fail: map val array", a, a1);
+ println("fail: map val array", a, a1)
}
}
@@ -82,36 +82,36 @@ type E struct { }
var e E
func interfacetest() {
- var i interface{};
+ var i interface{}
- i = a;
- a1 := i.([]int);
+ i = a
+ a1 := i.([]int)
if !SameArray(a, a1) {
- println("interface <-> []int", a, a1);
+ println("interface <-> []int", a, a1)
}
- pa := new([]int);
- *pa = a;
- i = pa;
- a1 = *i.(*[]int);
+ pa := new([]int)
+ *pa = a
+ i = pa
+ a1 = *i.(*[]int)
if !SameArray(a, a1) {
- println("interface <-> *[]int", a, a1);
+ println("interface <-> *[]int", a, a1)
}
- i = t;
- t1 := i.(T);
+ i = t
+ t1 := i.(T)
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
- println("interface <-> struct", t1.a, t1.b, t1.c, t1.d);
+ println("interface <-> struct", t1.a, t1.b, t1.c, t1.d)
}
- i = e;
- e1 := i.(E);
+ i = e
+ e1 := i.(E)
// nothing to check; just verify it doesn't crash
- _ = e1;
+ _ = e1
}
func main() {
- arraycmptest();
- maptest();
- chantest();
- interfacetest();
+ arraycmptest()
+ maptest()
+ chantest()
+ interfacetest()
}
diff --git a/test/blank.go b/test/blank.go
index 7175964f7..6e69f8aaa 100644
--- a/test/blank.go
+++ b/test/blank.go
@@ -11,7 +11,7 @@ import _ "fmt"
var call string
type T struct {
- _, _, _ int;
+ _, _, _ int
}
func (T) _() {
@@ -21,11 +21,11 @@ func (T) _() {
}
const (
- c0 = iota;
- _;
- _;
- _;
- c4;
+ c0 = iota
+ _
+ _
+ _
+ c4
)
var ints = []string {
@@ -35,12 +35,12 @@ var ints = []string {
}
func f() (int, int) {
- call += "f";
+ call += "f"
return 1,2
}
func g() (float, float) {
- call += "g";
+ call += "g"
return 3,4
}
@@ -48,54 +48,54 @@ func h(_ int, _ float) {
}
func i() int {
- call += "i";
- return 23;
+ call += "i"
+ return 23
}
-var _ = i();
+var _ = i()
func main() {
if call != "i" {panic("init did not run")}
- call = "";
- _, _ = f();
- a, _ := f();
+ call = ""
+ _, _ = f()
+ a, _ := f()
if a != 1 {panic(a)}
- b, _ := g();
+ b, _ := g()
if b != 3 {panic(b)}
- _, a = f();
+ _, a = f()
if a != 2 {panic(a)}
- _, b = g();
+ _, b = g()
if b != 4 {panic(b)}
- _ = i();
+ _ = i()
if call != "ffgfgi" {panic(call)}
if c4 != 4 {panic(c4)}
- out := "";
+ out := ""
for _, s := range ints {
- out += s;
+ out += s
}
if out != "123" {panic(out)}
- sum := 0;
- for s, _ := range ints {
- sum += s;
+ sum := 0
+ for s := range ints {
+ sum += s
}
if sum != 3 {panic(sum)}
- h(a,b);
+ h(a,b)
}
// useless but legal
-var _ int = 1;
-var _ = 2;
-var _, _ = 3, 4;
-const _ = 3;
-const _, _ = 4, 5;
-type _ int;
+var _ int = 1
+var _ = 2
+var _, _ = 3, 4
+const _ = 3
+const _, _ = 4, 5
+type _ int
func _() {
panic("oops")
}
func ff() {
- var _ int = 1;
+ var _ int = 1
}
diff --git a/test/blank1.go b/test/blank1.go
index 2fa6e9f8f..5bc1efce5 100644
--- a/test/blank1.go
+++ b/test/blank1.go
@@ -7,6 +7,6 @@
package _ // ERROR "invalid package name _"
func main() {
- _(); // ERROR "cannot use _ as value"
- x := _+1; // ERROR "cannot use _ as value"
+ _() // ERROR "cannot use _ as value"
+ x := _+1 // ERROR "cannot use _ as value"
}
diff --git a/test/chan/fifo.go b/test/chan/fifo.go
index 00a297a60..0dddfcaa0 100644
--- a/test/chan/fifo.go
+++ b/test/chan/fifo.go
@@ -13,20 +13,20 @@ import "os"
const N = 10
func AsynchFifo() {
- ch := make(chan int, N);
+ ch := make(chan int, N)
for i := 0; i < N; i++ {
ch <- i
}
for i := 0; i < N; i++ {
if <-ch != i {
- print("bad receive\n");
- os.Exit(1);
+ print("bad receive\n")
+ os.Exit(1)
}
}
}
func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) {
- <-in;
+ <-in
if <-ch != val {
panic(val)
}
@@ -35,15 +35,15 @@ func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) {
// thread together a daisy chain to read the elements in sequence
func SynchFifo() {
- ch := make(chan int);
- in := make(chan int);
- start := in;
+ ch := make(chan int)
+ in := make(chan int)
+ start := in
for i := 0; i < N; i++ {
- out := make(chan int);
- go Chain(ch, i, in, out);
- in = out;
+ out := make(chan int)
+ go Chain(ch, i, in, out)
+ in = out
}
- start <- 0;
+ start <- 0
for i := 0; i < N; i++ {
ch <- i
}
@@ -51,7 +51,7 @@ func SynchFifo() {
}
func main() {
- AsynchFifo();
- SynchFifo();
+ AsynchFifo()
+ SynchFifo()
}
diff --git a/test/chan/goroutines.go b/test/chan/goroutines.go
index cee8a18ac..d8f8803df 100644
--- a/test/chan/goroutines.go
+++ b/test/chan/goroutines.go
@@ -10,32 +10,32 @@
package main
import (
- "os";
- "strconv";
+ "os"
+ "strconv"
)
func f(left, right chan int) {
- left <- <-right;
+ left <- <-right
}
func main() {
- var n = 10000;
+ var n = 10000
if len(os.Args) > 1 {
- var err os.Error;
- n, err = strconv.Atoi(os.Args[1]);
+ var err os.Error
+ n, err = strconv.Atoi(os.Args[1])
if err != nil {
- print("bad arg\n");
- os.Exit(1);
+ print("bad arg\n")
+ os.Exit(1)
}
}
- leftmost := make(chan int);
- right := leftmost;
- left := leftmost;
+ leftmost := make(chan int)
+ right := leftmost
+ left := leftmost
for i := 0; i < n; i++ {
- right = make(chan int);
- go f(left, right);
- left = right;
+ right = make(chan int)
+ go f(left, right)
+ left = right
}
- go func(c chan int) { c <- 1 }(right);
- <-leftmost;
+ go func(c chan int) { c <- 1 }(right)
+ <-leftmost
}
diff --git a/test/chan/nonblock.go b/test/chan/nonblock.go
index 2bc5b6cb2..52f04bfb1 100644
--- a/test/chan/nonblock.go
+++ b/test/chan/nonblock.go
@@ -69,6 +69,8 @@ func sleep() {
runtime.Gosched()
}
+const maxTries = 10000 // Up to 100ms per test.
+
func main() {
var i32 int32
var i64 int64
@@ -105,24 +107,29 @@ func main() {
}
go i32receiver(c32, sync)
- sleep()
- ok = c32 <- 123
- if !ok {
- println("i32receiver buffer=", buffer)
- panic("fail")
+ try := 0
+ for !(c32 <- 123) {
+ try++
+ if try > maxTries {
+ println("i32receiver buffer=", buffer)
+ panic("fail")
+ }
+ sleep()
}
<-sync
go i32sender(c32, sync)
if buffer > 0 {
<-sync
- } else {
- sleep()
}
- i32, ok = <-c32
- if !ok {
- println("i32sender buffer=", buffer)
- panic("fail")
+ try = 0
+ for i32, ok = <-c32; !ok; i32, ok = <-c32 {
+ try++
+ if try > maxTries {
+ println("i32sender buffer=", buffer)
+ panic("fail")
+ }
+ sleep()
}
if i32 != 234 {
panic("i32sender value")
@@ -132,22 +139,27 @@ func main() {
}
go i64receiver(c64, sync)
- sleep()
- ok = c64 <- 123456
- if !ok {
- panic("i64receiver")
+ try = 0
+ for !(c64 <- 123456) {
+ try++
+ if try > maxTries {
+ panic("i64receiver")
+ }
+ sleep()
}
<-sync
go i64sender(c64, sync)
if buffer > 0 {
<-sync
- } else {
- sleep()
}
- i64, ok = <-c64
- if !ok {
- panic("i64sender")
+ try = 0
+ for i64, ok = <-c64; !ok; i64, ok = <-c64 {
+ try++
+ if try > maxTries {
+ panic("i64sender")
+ }
+ sleep()
}
if i64 != 234567 {
panic("i64sender value")
@@ -157,22 +169,27 @@ func main() {
}
go breceiver(cb, sync)
- sleep()
- ok = cb <- true
- if !ok {
- panic("breceiver")
+ try = 0
+ for !(cb <- true) {
+ try++
+ if try > maxTries {
+ panic("breceiver")
+ }
+ sleep()
}
<-sync
go bsender(cb, sync)
if buffer > 0 {
<-sync
- } else {
- sleep()
}
- b, ok = <-cb
- if !ok {
- panic("bsender")
+ try = 0
+ for b, ok = <-cb; !ok; b, ok = <-cb {
+ try++
+ if try > maxTries {
+ panic("bsender")
+ }
+ sleep()
}
if !b {
panic("bsender value")
@@ -182,22 +199,27 @@ func main() {
}
go sreceiver(cs, sync)
- sleep()
- ok = cs <- "hello"
- if !ok {
- panic("sreceiver")
+ try = 0
+ for !(cs <- "hello") {
+ try++
+ if try > maxTries {
+ panic("sreceiver")
+ }
+ sleep()
}
<-sync
go ssender(cs, sync)
if buffer > 0 {
<-sync
- } else {
- sleep()
}
- s, ok = <-cs
- if !ok {
- panic("ssender")
+ try = 0
+ for s, ok = <-cs; !ok; s, ok = <-cs {
+ try++
+ if try > maxTries {
+ panic("ssender")
+ }
+ sleep()
}
if s != "hello again" {
panic("ssender value")
diff --git a/test/chan/perm.go b/test/chan/perm.go
index 502e787a5..d08c03519 100644
--- a/test/chan/perm.go
+++ b/test/chan/perm.go
@@ -7,51 +7,51 @@
package main
var (
- cr <-chan int;
- cs chan<- int;
- c chan int;
+ cr <-chan int
+ cs chan<- int
+ c chan int
)
func main() {
- cr = c; // ok
- cs = c; // ok
- c = cr; // ERROR "illegal types|incompatible|cannot"
- c = cs; // ERROR "illegal types|incompatible|cannot"
- cr = cs; // ERROR "illegal types|incompatible|cannot"
- cs = cr; // ERROR "illegal types|incompatible|cannot"
-
- c <- 0; // ok
- ok := c <- 0; // ok
- _ = ok;
- <-c; // ok
- x, ok := <-c; // ok
- _, _ = x, ok;
-
- cr <- 0; // ERROR "send"
- ok = cr <- 0; // ERROR "send"
- _ = ok;
- <-cr; // ok
- x, ok = <-cr; // ok
- _, _ = x, ok;
-
- cs <- 0; // ok
- ok = cs <- 0; // ok
- _ = ok;
- <-cs; // ERROR "receive"
- x, ok = <-cs; // ERROR "receive"
- _, _ = x, ok;
+ cr = c // ok
+ cs = c // ok
+ c = cr // ERROR "illegal types|incompatible|cannot"
+ c = cs // ERROR "illegal types|incompatible|cannot"
+ cr = cs // ERROR "illegal types|incompatible|cannot"
+ cs = cr // ERROR "illegal types|incompatible|cannot"
+
+ c <- 0 // ok
+ ok := c <- 0 // ok
+ _ = ok
+ <-c // ok
+ x, ok := <-c // ok
+ _, _ = x, ok
+
+ cr <- 0 // ERROR "send"
+ ok = cr <- 0 // ERROR "send"
+ _ = ok
+ <-cr // ok
+ x, ok = <-cr // ok
+ _, _ = x, ok
+
+ cs <- 0 // ok
+ ok = cs <- 0 // ok
+ _ = ok
+ <-cs // ERROR "receive"
+ x, ok = <-cs // ERROR "receive"
+ _, _ = x, ok
select {
case c <- 0: // ok
case x := <-c: // ok
- _ = x;
+ _ = x
case cr <- 0: // ERROR "send"
case x := <-cr: // ok
- _ = x;
+ _ = x
- case cs <- 0: // ok;
+ case cs <- 0: // ok
case x := <-cs: // ERROR "receive"
- _ = x;
+ _ = x
}
}
diff --git a/test/chan/powser1.go b/test/chan/powser1.go
index bb36b1594..dc4ff5325 100644
--- a/test/chan/powser1.go
+++ b/test/chan/powser1.go
@@ -16,7 +16,7 @@ package main
import "os"
type rat struct {
- num, den int64; // numerator, denominator
+ num, den int64 // numerator, denominator
}
func (u rat) pr() {
@@ -33,9 +33,9 @@ func (u rat) eq(c rat) bool {
}
type dch struct {
- req chan int;
- dat chan rat;
- nam int;
+ req chan int
+ dat chan rat
+ nam int
}
type dch2 [2] *dch
@@ -45,20 +45,20 @@ var chnameserial int
var seqno int
func mkdch() *dch {
- c := chnameserial % len(chnames);
- chnameserial++;
- d := new(dch);
- d.req = make(chan int);
- d.dat = make(chan rat);
- d.nam = c;
- return d;
+ c := chnameserial % len(chnames)
+ chnameserial++
+ d := new(dch)
+ d.req = make(chan int)
+ d.dat = make(chan rat)
+ d.nam = c
+ return d
}
func mkdch2() *dch2 {
- d2 := new(dch2);
- d2[0] = mkdch();
- d2[1] = mkdch();
- return d2;
+ d2 := new(dch2)
+ d2[0] = mkdch()
+ d2[1] = mkdch()
+ return d2
}
// split reads a single demand channel and replicates its
@@ -76,98 +76,97 @@ func mkdch2() *dch2 {
// generation to begin servicing out[1].
func dosplit(in *dch, out *dch2, wait chan int ) {
- var t *dch;
- both := false; // do not service both channels
+ both := false // do not service both channels
select {
case <-out[0].req:
- ;
+
case <-wait:
- both = true;
+ both = true
select {
case <-out[0].req:
- ;
+
case <-out[1].req:
- t=out[0]; out[0]=out[1]; out[1]=t;
+ out[0], out[1] = out[1], out[0]
}
}
- seqno++;
- in.req <- seqno;
- release := make(chan int);
- go dosplit(in, out, release);
- dat := <-in.dat;
- out[0].dat <- dat;
+ seqno++
+ in.req <- seqno
+ release := make(chan int)
+ go dosplit(in, out, release)
+ dat := <-in.dat
+ out[0].dat <- dat
if !both {
<-wait
}
- <-out[1].req;
- out[1].dat <- dat;
- release <- 0;
+ <-out[1].req
+ out[1].dat <- dat
+ release <- 0
}
func split(in *dch, out *dch2) {
- release := make(chan int);
- go dosplit(in, out, release);
- release <- 0;
+ release := make(chan int)
+ go dosplit(in, out, release)
+ release <- 0
}
func put(dat rat, out *dch) {
- <-out.req;
- out.dat <- dat;
+ <-out.req
+ out.dat <- dat
}
func get(in *dch) rat {
- seqno++;
- in.req <- seqno;
- return <-in.dat;
+ seqno++
+ in.req <- seqno
+ return <-in.dat
}
// Get one rat from each of n demand channels
func getn(in []*dch) []rat {
- n := len(in);
- if n != 2 { panic("bad n in getn") };
- req := new([2] chan int);
- dat := new([2] chan rat);
- out := make([]rat, 2);
- var i int;
- var it rat;
+ n := len(in)
+ if n != 2 { panic("bad n in getn") }
+ req := new([2] chan int)
+ dat := new([2] chan rat)
+ out := make([]rat, 2)
+ var i int
+ var it rat
for i=0; i<n; i++ {
- req[i] = in[i].req;
- dat[i] = nil;
+ req[i] = in[i].req
+ dat[i] = nil
}
for n=2*n; n>0; n-- {
- seqno++;
+ seqno++
select {
case req[0] <- seqno:
- dat[0] = in[0].dat;
- req[0] = nil;
+ dat[0] = in[0].dat
+ req[0] = nil
case req[1] <- seqno:
- dat[1] = in[1].dat;
- req[1] = nil;
+ dat[1] = in[1].dat
+ req[1] = nil
case it = <-dat[0]:
- out[0] = it;
- dat[0] = nil;
+ out[0] = it
+ dat[0] = nil
case it = <-dat[1]:
- out[1] = it;
- dat[1] = nil;
+ out[1] = it
+ dat[1] = nil
}
}
- return out;
+ return out
}
// Get one rat from each of 2 demand channels
func get2(in0 *dch, in1 *dch) []rat {
- return getn([]*dch{in0, in1});
+ return getn([]*dch{in0, in1})
}
func copy(in *dch, out *dch) {
for {
- <-out.req;
- out.dat <- get(in);
+ <-out.req
+ out.dat <- get(in)
}
}
@@ -177,8 +176,8 @@ func repeat(dat rat, out *dch) {
}
}
-type PS *dch; // power series
-type PS2 *[2] PS; // pair of power series
+type PS *dch // power series
+type PS2 *[2] PS // pair of power series
var Ones PS
var Twos PS
@@ -208,29 +207,29 @@ func gcd (u, v int64) int64 {
// Make a rational from two ints and from one int
func i2tor(u, v int64) rat {
- g := gcd(u,v);
- var r rat;
+ g := gcd(u,v)
+ var r rat
if v > 0 {
- r.num = u/g;
- r.den = v/g;
+ r.num = u/g
+ r.den = v/g
} else {
- r.num = -u/g;
- r.den = -v/g;
+ r.num = -u/g
+ r.den = -v/g
}
- return r;
+ return r
}
func itor(u int64) rat {
- return i2tor(u, 1);
+ return i2tor(u, 1)
}
-var zero rat;
-var one rat;
+var zero rat
+var one rat
// End mark and end test
-var finis rat;
+var finis rat
func end(u rat) int64 {
if u.den==0 { return 1 }
@@ -240,68 +239,68 @@ func end(u rat) int64 {
// Operations on rationals
func add(u, v rat) rat {
- g := gcd(u.den,v.den);
- return i2tor(u.num*(v.den/g)+v.num*(u.den/g),u.den*(v.den/g));
+ g := gcd(u.den,v.den)
+ return i2tor(u.num*(v.den/g)+v.num*(u.den/g),u.den*(v.den/g))
}
func mul(u, v rat) rat {
- g1 := gcd(u.num,v.den);
- g2 := gcd(u.den,v.num);
- var r rat;
- r.num = (u.num/g1)*(v.num/g2);
- r.den = (u.den/g2)*(v.den/g1);
- return r;
+ g1 := gcd(u.num,v.den)
+ g2 := gcd(u.den,v.num)
+ var r rat
+ r.num = (u.num/g1)*(v.num/g2)
+ r.den = (u.den/g2)*(v.den/g1)
+ return r
}
func neg(u rat) rat {
- return i2tor(-u.num, u.den);
+ return i2tor(-u.num, u.den)
}
func sub(u, v rat) rat {
- return add(u, neg(v));
+ return add(u, neg(v))
}
func inv(u rat) rat { // invert a rat
if u.num == 0 { panic("zero divide in inv") }
- return i2tor(u.den, u.num);
+ return i2tor(u.den, u.num)
}
// print eval in floating point of PS at x=c to n terms
func evaln(c rat, U PS, n int) {
- xn := float64(1);
- x := float64(c.num)/float64(c.den);
- val := float64(0);
+ xn := float64(1)
+ x := float64(c.num)/float64(c.den)
+ val := float64(0)
for i:=0; i<n; i++ {
- u := get(U);
+ u := get(U)
if end(u) != 0 {
- break;
+ break
}
- val = val + x * float64(u.num)/float64(u.den);
- xn = xn*x;
+ val = val + x * float64(u.num)/float64(u.den)
+ xn = xn*x
}
- print(val, "\n");
+ print(val, "\n")
}
// Print n terms of a power series
func printn(U PS, n int) {
- done := false;
+ done := false
for ; !done && n>0; n-- {
- u := get(U);
+ u := get(U)
if end(u) != 0 {
done = true
} else {
u.pr()
}
}
- print(("\n"));
+ print(("\n"))
}
// Evaluate n terms of power series U at x=c
func eval(c rat, U PS, n int) rat {
if n==0 { return zero }
- y := get(U);
+ y := get(U)
if end(y) != 0 { return zero }
- return add(y,mul(c,eval(c,U,n-1)));
+ return add(y,mul(c,eval(c,U,n-1)))
}
// Power-series constructors return channels on which power
@@ -311,105 +310,105 @@ func eval(c rat, U PS, n int) rat {
// Make a pair of power series identical to a given power series
func Split(U PS) *dch2 {
- UU := mkdch2();
- go split(U,UU);
- return UU;
+ UU := mkdch2()
+ go split(U,UU)
+ return UU
}
// Add two power series
func Add(U, V PS) PS {
- Z := mkPS();
+ Z := mkPS()
go func() {
- var uv []rat;
+ var uv []rat
for {
- <-Z.req;
- uv = get2(U,V);
+ <-Z.req
+ uv = get2(U,V)
switch end(uv[0])+2*end(uv[1]) {
case 0:
- Z.dat <- add(uv[0], uv[1]);
+ Z.dat <- add(uv[0], uv[1])
case 1:
- Z.dat <- uv[1];
- copy(V,Z);
+ Z.dat <- uv[1]
+ copy(V,Z)
case 2:
- Z.dat <- uv[0];
- copy(U,Z);
+ Z.dat <- uv[0]
+ copy(U,Z)
case 3:
- Z.dat <- finis;
+ Z.dat <- finis
}
}
- }();
- return Z;
+ }()
+ return Z
}
// Multiply a power series by a constant
func Cmul(c rat,U PS) PS {
- Z := mkPS();
+ Z := mkPS()
go func() {
- done := false;
+ done := false
for !done {
- <-Z.req;
- u := get(U);
+ <-Z.req
+ u := get(U)
if end(u) != 0 {
done = true
} else {
Z.dat <- mul(c,u)
}
}
- Z.dat <- finis;
- }();
- return Z;
+ Z.dat <- finis
+ }()
+ return Z
}
// Subtract
func Sub(U, V PS) PS {
- return Add(U, Cmul(neg(one), V));
+ return Add(U, Cmul(neg(one), V))
}
// Multiply a power series by the monomial x^n
func Monmul(U PS, n int) PS {
- Z := mkPS();
+ Z := mkPS()
go func() {
for ; n>0; n-- { put(zero,Z) }
- copy(U,Z);
- }();
- return Z;
+ copy(U,Z)
+ }()
+ return Z
}
// Multiply by x
func Xmul(U PS) PS {
- return Monmul(U,1);
+ return Monmul(U,1)
}
func Rep(c rat) PS {
- Z := mkPS();
- go repeat(c,Z);
- return Z;
+ Z := mkPS()
+ go repeat(c,Z)
+ return Z
}
// Monomial c*x^n
func Mon(c rat, n int) PS {
- Z:=mkPS();
+ Z:=mkPS()
go func() {
if(c.num!=0) {
for ; n>0; n=n-1 { put(zero,Z) }
- put(c,Z);
+ put(c,Z)
}
- put(finis,Z);
- }();
- return Z;
+ put(finis,Z)
+ }()
+ return Z
}
func Shift(c rat, U PS) PS {
- Z := mkPS();
+ Z := mkPS()
go func() {
- put(c,Z);
- copy(U,Z);
- }();
- return Z;
+ put(c,Z)
+ copy(U,Z)
+ }()
+ return Z
}
// simple pole at 1: 1/(1-x) = 1 1 1 1 1 ...
@@ -419,17 +418,17 @@ func Shift(c rat, U PS) PS {
/*
func Poly(a []rat) PS {
- Z:=mkPS();
+ Z:=mkPS()
begin func(a []rat, Z PS) {
- j:=0;
- done:=0;
+ j:=0
+ done:=0
for j=len(a); !done&&j>0; j=j-1)
- if(a[j-1].num!=0) done=1;
- i:=0;
- for(; i<j; i=i+1) put(a[i],Z);
- put(finis,Z);
- }();
- return Z;
+ if(a[j-1].num!=0) done=1
+ i:=0
+ for(; i<j; i=i+1) put(a[i],Z)
+ put(finis,Z)
+ }()
+ return Z
}
*/
@@ -439,82 +438,82 @@ func Poly(a []rat) PS {
// then UV = u*v + x*(u*VV+v*UU) + x*x*UU*VV
func Mul(U, V PS) PS {
- Z:=mkPS();
+ Z:=mkPS()
go func() {
- <-Z.req;
- uv := get2(U,V);
+ <-Z.req
+ uv := get2(U,V)
if end(uv[0])!=0 || end(uv[1]) != 0 {
- Z.dat <- finis;
+ Z.dat <- finis
} else {
- Z.dat <- mul(uv[0],uv[1]);
- UU := Split(U);
- VV := Split(V);
- W := Add(Cmul(uv[0],VV[0]),Cmul(uv[1],UU[0]));
- <-Z.req;
- Z.dat <- get(W);
- copy(Add(W,Mul(UU[1],VV[1])),Z);
+ Z.dat <- mul(uv[0],uv[1])
+ UU := Split(U)
+ VV := Split(V)
+ W := Add(Cmul(uv[0],VV[0]),Cmul(uv[1],UU[0]))
+ <-Z.req
+ Z.dat <- get(W)
+ copy(Add(W,Mul(UU[1],VV[1])),Z)
}
- }();
- return Z;
+ }()
+ return Z
}
// Differentiate
func Diff(U PS) PS {
- Z:=mkPS();
+ Z:=mkPS()
go func() {
- <-Z.req;
- u := get(U);
+ <-Z.req
+ u := get(U)
if end(u) == 0 {
- done:=false;
+ done:=false
for i:=1; !done; i++ {
- u = get(U);
+ u = get(U)
if end(u) != 0 {
done = true
} else {
- Z.dat <- mul(itor(int64(i)),u);
- <-Z.req;
+ Z.dat <- mul(itor(int64(i)),u)
+ <-Z.req
}
}
}
- Z.dat <- finis;
- }();
- return Z;
+ Z.dat <- finis
+ }()
+ return Z
}
// Integrate, with const of integration
func Integ(c rat,U PS) PS {
- Z:=mkPS();
+ Z:=mkPS()
go func() {
- put(c,Z);
- done:=false;
+ put(c,Z)
+ done:=false
for i:=1; !done; i++ {
- <-Z.req;
- u := get(U);
+ <-Z.req
+ u := get(U)
if end(u) != 0 { done= true }
- Z.dat <- mul(i2tor(1,int64(i)),u);
+ Z.dat <- mul(i2tor(1,int64(i)),u)
}
- Z.dat <- finis;
- }();
- return Z;
+ Z.dat <- finis
+ }()
+ return Z
}
// Binomial theorem (1+x)^c
func Binom(c rat) PS {
- Z:=mkPS();
+ Z:=mkPS()
go func() {
- n := 1;
- t := itor(1);
+ n := 1
+ t := itor(1)
for c.num!=0 {
- put(t,Z);
- t = mul(mul(t,c),i2tor(1,int64(n)));
- c = sub(c,one);
- n++;
+ put(t,Z)
+ t = mul(mul(t,c),i2tor(1,int64(n)))
+ c = sub(c,one)
+ n++
}
- put(finis,Z);
- }();
- return Z;
+ put(finis,Z)
+ }()
+ return Z
}
// Reciprocal of a power series
@@ -523,19 +522,19 @@ func Binom(c rat) PS {
// (u+x*UU)*(z+x*ZZ) = 1
// z = 1/u
// u*ZZ + z*UU +x*UU*ZZ = 0
-// ZZ = -UU*(z+x*ZZ)/u;
+// ZZ = -UU*(z+x*ZZ)/u
func Recip(U PS) PS {
- Z:=mkPS();
+ Z:=mkPS()
go func() {
- ZZ:=mkPS2();
- <-Z.req;
- z := inv(get(U));
- Z.dat <- z;
- split(Mul(Cmul(neg(z),U),Shift(z,ZZ[0])),ZZ);
- copy(ZZ[1],Z);
- }();
- return Z;
+ ZZ:=mkPS2()
+ <-Z.req
+ z := inv(get(U))
+ Z.dat <- z
+ split(Mul(Cmul(neg(z),U),Shift(z,ZZ[0])),ZZ)
+ copy(ZZ[1],Z)
+ }()
+ return Z
}
// Exponential of a power series with constant term 0
@@ -546,9 +545,9 @@ func Recip(U PS) PS {
// integrate to get Z
func Exp(U PS) PS {
- ZZ := mkPS2();
- split(Integ(one,Mul(ZZ[0],Diff(U))),ZZ);
- return ZZ[1];
+ ZZ := mkPS2()
+ split(Integ(one,Mul(ZZ[0],Diff(U))),ZZ)
+ return ZZ[1]
}
// Substitute V for x in U, where the leading term of V is zero
@@ -558,69 +557,69 @@ func Exp(U PS) PS {
// bug: a nonzero constant term is ignored
func Subst(U, V PS) PS {
- Z:= mkPS();
+ Z:= mkPS()
go func() {
- VV := Split(V);
- <-Z.req;
- u := get(U);
- Z.dat <- u;
+ VV := Split(V)
+ <-Z.req
+ u := get(U)
+ Z.dat <- u
if end(u) == 0 {
if end(get(VV[0])) != 0 {
- put(finis,Z);
+ put(finis,Z)
} else {
- copy(Mul(VV[0],Subst(U,VV[1])),Z);
+ copy(Mul(VV[0],Subst(U,VV[1])),Z)
}
}
- }();
- return Z;
+ }()
+ return Z
}
// Monomial Substition: U(c x^n)
// Each Ui is multiplied by c^i and followed by n-1 zeros
func MonSubst(U PS, c0 rat, n int) PS {
- Z:= mkPS();
+ Z:= mkPS()
go func() {
- c := one;
+ c := one
for {
- <-Z.req;
- u := get(U);
- Z.dat <- mul(u, c);
- c = mul(c, c0);
+ <-Z.req
+ u := get(U)
+ Z.dat <- mul(u, c)
+ c = mul(c, c0)
if end(u) != 0 {
- Z.dat <- finis;
- break;
+ Z.dat <- finis
+ break
}
for i := 1; i < n; i++ {
- <-Z.req;
- Z.dat <- zero;
+ <-Z.req
+ Z.dat <- zero
}
}
- }();
- return Z;
+ }()
+ return Z
}
func Init() {
- chnameserial = -1;
- seqno = 0;
- chnames = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- zero = itor(0);
- one = itor(1);
- finis = i2tor(1,0);
- Ones = Rep(one);
- Twos = Rep(itor(2));
+ chnameserial = -1
+ seqno = 0
+ chnames = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+ zero = itor(0)
+ one = itor(1)
+ finis = i2tor(1,0)
+ Ones = Rep(one)
+ Twos = Rep(itor(2))
}
func check(U PS, c rat, count int, str string) {
for i := 0; i < count; i++ {
- r := get(U);
+ r := get(U)
if !r.eq(c) {
- print("got: ");
- r.pr();
- print("should get ");
- c.pr();
- print("\n");
+ print("got: ")
+ r.pr()
+ print("should get ")
+ c.pr()
+ print("\n")
panic(str)
}
}
@@ -629,82 +628,82 @@ func check(U PS, c rat, count int, str string) {
const N=10
func checka(U PS, a []rat, str string) {
for i := 0; i < N; i++ {
- check(U, a[i], 1, str);
+ check(U, a[i], 1, str)
}
}
func main() {
- Init();
+ Init()
if len(os.Args) > 1 { // print
- print("Ones: "); printn(Ones, 10);
- print("Twos: "); printn(Twos, 10);
- print("Add: "); printn(Add(Ones, Twos), 10);
- print("Diff: "); printn(Diff(Ones), 10);
- print("Integ: "); printn(Integ(zero, Ones), 10);
- print("CMul: "); printn(Cmul(neg(one), Ones), 10);
- print("Sub: "); printn(Sub(Ones, Twos), 10);
- print("Mul: "); printn(Mul(Ones, Ones), 10);
- print("Exp: "); printn(Exp(Ones), 15);
- print("MonSubst: "); printn(MonSubst(Ones, neg(one), 2), 10);
- print("ATan: "); printn(Integ(zero, MonSubst(Ones, neg(one), 2)), 10);
+ print("Ones: "); printn(Ones, 10)
+ print("Twos: "); printn(Twos, 10)
+ print("Add: "); printn(Add(Ones, Twos), 10)
+ print("Diff: "); printn(Diff(Ones), 10)
+ print("Integ: "); printn(Integ(zero, Ones), 10)
+ print("CMul: "); printn(Cmul(neg(one), Ones), 10)
+ print("Sub: "); printn(Sub(Ones, Twos), 10)
+ print("Mul: "); printn(Mul(Ones, Ones), 10)
+ print("Exp: "); printn(Exp(Ones), 15)
+ print("MonSubst: "); printn(MonSubst(Ones, neg(one), 2), 10)
+ print("ATan: "); printn(Integ(zero, MonSubst(Ones, neg(one), 2)), 10)
} else { // test
- check(Ones, one, 5, "Ones");
- check(Add(Ones, Ones), itor(2), 0, "Add Ones Ones"); // 1 1 1 1 1
- check(Add(Ones, Twos), itor(3), 0, "Add Ones Twos"); // 3 3 3 3 3
- a := make([]rat, N);
- d := Diff(Ones);
+ check(Ones, one, 5, "Ones")
+ check(Add(Ones, Ones), itor(2), 0, "Add Ones Ones") // 1 1 1 1 1
+ check(Add(Ones, Twos), itor(3), 0, "Add Ones Twos") // 3 3 3 3 3
+ a := make([]rat, N)
+ d := Diff(Ones)
for i:=0; i < N; i++ {
a[i] = itor(int64(i+1))
}
- checka(d, a, "Diff"); // 1 2 3 4 5
- in := Integ(zero, Ones);
- a[0] = zero; // integration constant
+ checka(d, a, "Diff") // 1 2 3 4 5
+ in := Integ(zero, Ones)
+ a[0] = zero // integration constant
for i:=1; i < N; i++ {
a[i] = i2tor(1, int64(i))
}
- checka(in, a, "Integ"); // 0 1 1/2 1/3 1/4 1/5
- check(Cmul(neg(one), Twos), itor(-2), 10, "CMul"); // -1 -1 -1 -1 -1
- check(Sub(Ones, Twos), itor(-1), 0, "Sub Ones Twos"); // -1 -1 -1 -1 -1
- m := Mul(Ones, Ones);
+ checka(in, a, "Integ") // 0 1 1/2 1/3 1/4 1/5
+ check(Cmul(neg(one), Twos), itor(-2), 10, "CMul") // -1 -1 -1 -1 -1
+ check(Sub(Ones, Twos), itor(-1), 0, "Sub Ones Twos") // -1 -1 -1 -1 -1
+ m := Mul(Ones, Ones)
for i:=0; i < N; i++ {
a[i] = itor(int64(i+1))
}
- checka(m, a, "Mul"); // 1 2 3 4 5
- e := Exp(Ones);
- a[0] = itor(1);
- a[1] = itor(1);
- a[2] = i2tor(3,2);
- a[3] = i2tor(13,6);
- a[4] = i2tor(73,24);
- a[5] = i2tor(167,40);
- a[6] = i2tor(4051,720);
- a[7] = i2tor(37633,5040);
- a[8] = i2tor(43817,4480);
- a[9] = i2tor(4596553,362880);
- checka(e, a, "Exp"); // 1 1 3/2 13/6 73/24
- at := Integ(zero, MonSubst(Ones, neg(one), 2));
+ checka(m, a, "Mul") // 1 2 3 4 5
+ e := Exp(Ones)
+ a[0] = itor(1)
+ a[1] = itor(1)
+ a[2] = i2tor(3,2)
+ a[3] = i2tor(13,6)
+ a[4] = i2tor(73,24)
+ a[5] = i2tor(167,40)
+ a[6] = i2tor(4051,720)
+ a[7] = i2tor(37633,5040)
+ a[8] = i2tor(43817,4480)
+ a[9] = i2tor(4596553,362880)
+ checka(e, a, "Exp") // 1 1 3/2 13/6 73/24
+ at := Integ(zero, MonSubst(Ones, neg(one), 2))
for c, i := 1, 0; i < N; i++ {
if i%2 == 0 {
a[i] = zero
} else {
- a[i] = i2tor(int64(c), int64(i));
+ a[i] = i2tor(int64(c), int64(i))
c *= -1
}
}
- checka(at, a, "ATan"); // 0 -1 0 -1/3 0 -1/5
+ checka(at, a, "ATan") // 0 -1 0 -1/3 0 -1/5
/*
- t := Revert(Integ(zero, MonSubst(Ones, neg(one), 2)));
- a[0] = zero;
- a[1] = itor(1);
- a[2] = zero;
- a[3] = i2tor(1,3);
- a[4] = zero;
- a[5] = i2tor(2,15);
- a[6] = zero;
- a[7] = i2tor(17,315);
- a[8] = zero;
- a[9] = i2tor(62,2835);
- checka(t, a, "Tan"); // 0 1 0 1/3 0 2/15
+ t := Revert(Integ(zero, MonSubst(Ones, neg(one), 2)))
+ a[0] = zero
+ a[1] = itor(1)
+ a[2] = zero
+ a[3] = i2tor(1,3)
+ a[4] = zero
+ a[5] = i2tor(2,15)
+ a[6] = zero
+ a[7] = i2tor(17,315)
+ a[8] = zero
+ a[9] = i2tor(62,2835)
+ checka(t, a, "Tan") // 0 1 0 1/3 0 2/15
*/
}
}
diff --git a/test/chan/powser2.go b/test/chan/powser2.go
index 0c523ac99..bc329270d 100644
--- a/test/chan/powser2.go
+++ b/test/chan/powser2.go
@@ -19,12 +19,12 @@ package main
import "os"
type rat struct {
- num, den int64; // numerator, denominator
+ num, den int64 // numerator, denominator
}
type item interface {
- pr();
- eq(c item) bool;
+ pr()
+ eq(c item) bool
}
func (u *rat) pr(){
@@ -37,14 +37,14 @@ func (u *rat) pr(){
}
func (u *rat) eq(c item) bool {
- c1 := c.(*rat);
+ c1 := c.(*rat)
return u.num == c1.num && u.den == c1.den
}
type dch struct {
- req chan int;
- dat chan item;
- nam int;
+ req chan int
+ dat chan item
+ nam int
}
type dch2 [2] *dch
@@ -54,20 +54,20 @@ var chnameserial int
var seqno int
func mkdch() *dch {
- c := chnameserial % len(chnames);
- chnameserial++;
- d := new(dch);
- d.req = make(chan int);
- d.dat = make(chan item);
- d.nam = c;
- return d;
+ c := chnameserial % len(chnames)
+ chnameserial++
+ d := new(dch)
+ d.req = make(chan int)
+ d.dat = make(chan item)
+ d.nam = c
+ return d
}
func mkdch2() *dch2 {
- d2 := new(dch2);
- d2[0] = mkdch();
- d2[1] = mkdch();
- return d2;
+ d2 := new(dch2)
+ d2[0] = mkdch()
+ d2[1] = mkdch()
+ return d2
}
// split reads a single demand channel and replicates its
@@ -85,98 +85,97 @@ func mkdch2() *dch2 {
// generation to begin servicing out[1].
func dosplit(in *dch, out *dch2, wait chan int ){
- var t *dch;
- both := false; // do not service both channels
+ both := false // do not service both channels
select {
case <-out[0].req:
- ;
+
case <-wait:
- both = true;
+ both = true
select {
case <-out[0].req:
- ;
+
case <-out[1].req:
- t=out[0]; out[0]=out[1]; out[1]=t;
+ out[0],out[1] = out[1], out[0]
}
}
- seqno++;
- in.req <- seqno;
- release := make(chan int);
- go dosplit(in, out, release);
- dat := <-in.dat;
- out[0].dat <- dat;
+ seqno++
+ in.req <- seqno
+ release := make(chan int)
+ go dosplit(in, out, release)
+ dat := <-in.dat
+ out[0].dat <- dat
if !both {
<-wait
}
- <-out[1].req;
- out[1].dat <- dat;
- release <- 0;
+ <-out[1].req
+ out[1].dat <- dat
+ release <- 0
}
func split(in *dch, out *dch2){
- release := make(chan int);
- go dosplit(in, out, release);
- release <- 0;
+ release := make(chan int)
+ go dosplit(in, out, release)
+ release <- 0
}
func put(dat item, out *dch){
- <-out.req;
- out.dat <- dat;
+ <-out.req
+ out.dat <- dat
}
func get(in *dch) *rat {
- seqno++;
- in.req <- seqno;
- return (<-in.dat).(*rat);
+ seqno++
+ in.req <- seqno
+ return (<-in.dat).(*rat)
}
// Get one item from each of n demand channels
func getn(in []*dch) []item {
- n:=len(in);
- if n != 2 { panic("bad n in getn") };
- req := make([] chan int, 2);
- dat := make([] chan item, 2);
- out := make([]item, 2);
- var i int;
- var it item;
+ n:=len(in)
+ if n != 2 { panic("bad n in getn") }
+ req := make([] chan int, 2)
+ dat := make([] chan item, 2)
+ out := make([]item, 2)
+ var i int
+ var it item
for i=0; i<n; i++ {
- req[i] = in[i].req;
- dat[i] = nil;
+ req[i] = in[i].req
+ dat[i] = nil
}
for n=2*n; n>0; n-- {
- seqno++;
+ seqno++
select{
case req[0] <- seqno:
- dat[0] = in[0].dat;
- req[0] = nil;
+ dat[0] = in[0].dat
+ req[0] = nil
case req[1] <- seqno:
- dat[1] = in[1].dat;
- req[1] = nil;
+ dat[1] = in[1].dat
+ req[1] = nil
case it = <-dat[0]:
- out[0] = it;
- dat[0] = nil;
+ out[0] = it
+ dat[0] = nil
case it = <-dat[1]:
- out[1] = it;
- dat[1] = nil;
+ out[1] = it
+ dat[1] = nil
}
}
- return out;
+ return out
}
// Get one item from each of 2 demand channels
func get2(in0 *dch, in1 *dch) []item {
- return getn([]*dch{in0, in1});
+ return getn([]*dch{in0, in1})
}
func copy(in *dch, out *dch){
for {
- <-out.req;
- out.dat <- get(in);
+ <-out.req
+ out.dat <- get(in)
}
}
@@ -186,8 +185,8 @@ func repeat(dat item, out *dch){
}
}
-type PS *dch; // power series
-type PS2 *[2] PS; // pair of power series
+type PS *dch // power series
+type PS2 *[2] PS // pair of power series
var Ones PS
var Twos PS
@@ -217,29 +216,29 @@ func gcd (u, v int64) int64{
// Make a rational from two ints and from one int
func i2tor(u, v int64) *rat{
- g := gcd(u,v);
- r := new(rat);
+ g := gcd(u,v)
+ r := new(rat)
if v > 0 {
- r.num = u/g;
- r.den = v/g;
+ r.num = u/g
+ r.den = v/g
} else {
- r.num = -u/g;
- r.den = -v/g;
+ r.num = -u/g
+ r.den = -v/g
}
- return r;
+ return r
}
func itor(u int64) *rat{
- return i2tor(u, 1);
+ return i2tor(u, 1)
}
-var zero *rat;
-var one *rat;
+var zero *rat
+var one *rat
// End mark and end test
-var finis *rat;
+var finis *rat
func end(u *rat) int64 {
if u.den==0 { return 1 }
@@ -249,72 +248,72 @@ func end(u *rat) int64 {
// Operations on rationals
func add(u, v *rat) *rat {
- g := gcd(u.den,v.den);
- return i2tor(u.num*(v.den/g)+v.num*(u.den/g),u.den*(v.den/g));
+ g := gcd(u.den,v.den)
+ return i2tor(u.num*(v.den/g)+v.num*(u.den/g),u.den*(v.den/g))
}
func mul(u, v *rat) *rat{
- g1 := gcd(u.num,v.den);
- g2 := gcd(u.den,v.num);
- r := new(rat);
- r.num =(u.num/g1)*(v.num/g2);
- r.den = (u.den/g2)*(v.den/g1);
- return r;
+ g1 := gcd(u.num,v.den)
+ g2 := gcd(u.den,v.num)
+ r := new(rat)
+ r.num =(u.num/g1)*(v.num/g2)
+ r.den = (u.den/g2)*(v.den/g1)
+ return r
}
func neg(u *rat) *rat{
- return i2tor(-u.num, u.den);
+ return i2tor(-u.num, u.den)
}
func sub(u, v *rat) *rat{
- return add(u, neg(v));
+ return add(u, neg(v))
}
func inv(u *rat) *rat{ // invert a rat
if u.num == 0 { panic("zero divide in inv") }
- return i2tor(u.den, u.num);
+ return i2tor(u.den, u.num)
}
// print eval in floating point of PS at x=c to n terms
func Evaln(c *rat, U PS, n int) {
- xn := float64(1);
- x := float64(c.num)/float64(c.den);
- val := float64(0);
+ xn := float64(1)
+ x := float64(c.num)/float64(c.den)
+ val := float64(0)
for i:=0; i<n; i++ {
- u := get(U);
+ u := get(U)
if end(u) != 0 {
- break;
+ break
}
- val = val + x * float64(u.num)/float64(u.den);
- xn = xn*x;
+ val = val + x * float64(u.num)/float64(u.den)
+ xn = xn*x
}
- print(val, "\n");
+ print(val, "\n")
}
// Print n terms of a power series
func Printn(U PS, n int){
- done := false;
+ done := false
for ; !done && n>0; n-- {
- u := get(U);
+ u := get(U)
if end(u) != 0 {
done = true
} else {
u.pr()
}
}
- print(("\n"));
+ print(("\n"))
}
func Print(U PS){
- Printn(U,1000000000);
+ Printn(U,1000000000)
}
// Evaluate n terms of power series U at x=c
func eval(c *rat, U PS, n int) *rat{
if n==0 { return zero }
- y := get(U);
+ y := get(U)
if end(y) != 0 { return zero }
- return add(y,mul(c,eval(c,U,n-1)));
+ return add(y,mul(c,eval(c,U,n-1)))
}
// Power-series constructors return channels on which power
@@ -324,105 +323,105 @@ func eval(c *rat, U PS, n int) *rat{
// Make a pair of power series identical to a given power series
func Split(U PS) *dch2{
- UU := mkdch2();
- go split(U,UU);
- return UU;
+ UU := mkdch2()
+ go split(U,UU)
+ return UU
}
// Add two power series
func Add(U, V PS) PS{
- Z := mkPS();
+ Z := mkPS()
go func(U, V, Z PS){
- var uv [] item;
+ var uv [] item
for {
- <-Z.req;
- uv = get2(U,V);
+ <-Z.req
+ uv = get2(U,V)
switch end(uv[0].(*rat))+2*end(uv[1].(*rat)) {
case 0:
- Z.dat <- add(uv[0].(*rat), uv[1].(*rat));
+ Z.dat <- add(uv[0].(*rat), uv[1].(*rat))
case 1:
- Z.dat <- uv[1];
- copy(V,Z);
+ Z.dat <- uv[1]
+ copy(V,Z)
case 2:
- Z.dat <- uv[0];
- copy(U,Z);
+ Z.dat <- uv[0]
+ copy(U,Z)
case 3:
- Z.dat <- finis;
+ Z.dat <- finis
}
}
- }(U, V, Z);
- return Z;
+ }(U, V, Z)
+ return Z
}
// Multiply a power series by a constant
func Cmul(c *rat,U PS) PS{
- Z := mkPS();
+ Z := mkPS()
go func(c *rat, U, Z PS){
- done := false;
+ done := false
for !done {
- <-Z.req;
- u := get(U);
+ <-Z.req
+ u := get(U)
if end(u) != 0 {
done = true
} else {
Z.dat <- mul(c,u)
}
}
- Z.dat <- finis;
- }(c, U, Z);
- return Z;
+ Z.dat <- finis
+ }(c, U, Z)
+ return Z
}
// Subtract
func Sub(U, V PS) PS{
- return Add(U, Cmul(neg(one), V));
+ return Add(U, Cmul(neg(one), V))
}
// Multiply a power series by the monomial x^n
func Monmul(U PS, n int) PS{
- Z := mkPS();
+ Z := mkPS()
go func(n int, U PS, Z PS){
for ; n>0; n-- { put(zero,Z) }
- copy(U,Z);
- }(n, U, Z);
- return Z;
+ copy(U,Z)
+ }(n, U, Z)
+ return Z
}
// Multiply by x
func Xmul(U PS) PS{
- return Monmul(U,1);
+ return Monmul(U,1)
}
func Rep(c *rat) PS{
- Z := mkPS();
- go repeat(c,Z);
- return Z;
+ Z := mkPS()
+ go repeat(c,Z)
+ return Z
}
// Monomial c*x^n
func Mon(c *rat, n int) PS{
- Z:=mkPS();
+ Z:=mkPS()
go func(c *rat, n int, Z PS){
if(c.num!=0) {
for ; n>0; n=n-1 { put(zero,Z) }
- put(c,Z);
+ put(c,Z)
}
- put(finis,Z);
- }(c, n, Z);
- return Z;
+ put(finis,Z)
+ }(c, n, Z)
+ return Z
}
func Shift(c *rat, U PS) PS{
- Z := mkPS();
+ Z := mkPS()
go func(c *rat, U, Z PS){
- put(c,Z);
- copy(U,Z);
- }(c, U, Z);
- return Z;
+ put(c,Z)
+ copy(U,Z)
+ }(c, U, Z)
+ return Z
}
// simple pole at 1: 1/(1-x) = 1 1 1 1 1 ...
@@ -432,17 +431,17 @@ func Shift(c *rat, U PS) PS{
/*
func Poly(a [] *rat) PS{
- Z:=mkPS();
+ Z:=mkPS()
begin func(a [] *rat, Z PS){
- j:=0;
- done:=0;
+ j:=0
+ done:=0
for j=len(a); !done&&j>0; j=j-1)
- if(a[j-1].num!=0) done=1;
- i:=0;
- for(; i<j; i=i+1) put(a[i],Z);
- put(finis,Z);
- }();
- return Z;
+ if(a[j-1].num!=0) done=1
+ i:=0
+ for(; i<j; i=i+1) put(a[i],Z)
+ put(finis,Z)
+ }()
+ return Z
}
*/
@@ -452,82 +451,82 @@ func Poly(a [] *rat) PS{
// then UV = u*v + x*(u*VV+v*UU) + x*x*UU*VV
func Mul(U, V PS) PS{
- Z:=mkPS();
+ Z:=mkPS()
go func(U, V, Z PS){
- <-Z.req;
- uv := get2(U,V);
+ <-Z.req
+ uv := get2(U,V)
if end(uv[0].(*rat))!=0 || end(uv[1].(*rat)) != 0 {
- Z.dat <- finis;
+ Z.dat <- finis
} else {
- Z.dat <- mul(uv[0].(*rat),uv[1].(*rat));
- UU := Split(U);
- VV := Split(V);
- W := Add(Cmul(uv[0].(*rat),VV[0]),Cmul(uv[1].(*rat),UU[0]));
- <-Z.req;
- Z.dat <- get(W);
- copy(Add(W,Mul(UU[1],VV[1])),Z);
+ Z.dat <- mul(uv[0].(*rat),uv[1].(*rat))
+ UU := Split(U)
+ VV := Split(V)
+ W := Add(Cmul(uv[0].(*rat),VV[0]),Cmul(uv[1].(*rat),UU[0]))
+ <-Z.req
+ Z.dat <- get(W)
+ copy(Add(W,Mul(UU[1],VV[1])),Z)
}
- }(U, V, Z);
- return Z;
+ }(U, V, Z)
+ return Z
}
// Differentiate
func Diff(U PS) PS{
- Z:=mkPS();
+ Z:=mkPS()
go func(U, Z PS){
- <-Z.req;
- u := get(U);
+ <-Z.req
+ u := get(U)
if end(u) == 0 {
- done:=false;
+ done:=false
for i:=1; !done; i++ {
- u = get(U);
+ u = get(U)
if end(u) != 0 {
done=true
} else {
- Z.dat <- mul(itor(int64(i)),u);
- <-Z.req;
+ Z.dat <- mul(itor(int64(i)),u)
+ <-Z.req
}
}
}
- Z.dat <- finis;
- }(U, Z);
- return Z;
+ Z.dat <- finis
+ }(U, Z)
+ return Z
}
// Integrate, with const of integration
func Integ(c *rat,U PS) PS{
- Z:=mkPS();
+ Z:=mkPS()
go func(c *rat, U, Z PS){
- put(c,Z);
- done:=false;
+ put(c,Z)
+ done:=false
for i:=1; !done; i++ {
- <-Z.req;
- u := get(U);
+ <-Z.req
+ u := get(U)
if end(u) != 0 { done= true }
- Z.dat <- mul(i2tor(1,int64(i)),u);
+ Z.dat <- mul(i2tor(1,int64(i)),u)
}
- Z.dat <- finis;
- }(c, U, Z);
- return Z;
+ Z.dat <- finis
+ }(c, U, Z)
+ return Z
}
// Binomial theorem (1+x)^c
func Binom(c *rat) PS{
- Z:=mkPS();
+ Z:=mkPS()
go func(c *rat, Z PS){
- n := 1;
- t := itor(1);
+ n := 1
+ t := itor(1)
for c.num!=0 {
- put(t,Z);
- t = mul(mul(t,c),i2tor(1,int64(n)));
- c = sub(c,one);
- n++;
+ put(t,Z)
+ t = mul(mul(t,c),i2tor(1,int64(n)))
+ c = sub(c,one)
+ n++
}
- put(finis,Z);
- }(c, Z);
- return Z;
+ put(finis,Z)
+ }(c, Z)
+ return Z
}
// Reciprocal of a power series
@@ -536,19 +535,19 @@ func Binom(c *rat) PS{
// (u+x*UU)*(z+x*ZZ) = 1
// z = 1/u
// u*ZZ + z*UU +x*UU*ZZ = 0
-// ZZ = -UU*(z+x*ZZ)/u;
+// ZZ = -UU*(z+x*ZZ)/u
func Recip(U PS) PS{
- Z:=mkPS();
+ Z:=mkPS()
go func(U, Z PS){
- ZZ:=mkPS2();
- <-Z.req;
- z := inv(get(U));
- Z.dat <- z;
- split(Mul(Cmul(neg(z),U),Shift(z,ZZ[0])),ZZ);
- copy(ZZ[1],Z);
- }(U, Z);
- return Z;
+ ZZ:=mkPS2()
+ <-Z.req
+ z := inv(get(U))
+ Z.dat <- z
+ split(Mul(Cmul(neg(z),U),Shift(z,ZZ[0])),ZZ)
+ copy(ZZ[1],Z)
+ }(U, Z)
+ return Z
}
// Exponential of a power series with constant term 0
@@ -559,9 +558,9 @@ func Recip(U PS) PS{
// integrate to get Z
func Exp(U PS) PS{
- ZZ := mkPS2();
- split(Integ(one,Mul(ZZ[0],Diff(U))),ZZ);
- return ZZ[1];
+ ZZ := mkPS2()
+ split(Integ(one,Mul(ZZ[0],Diff(U))),ZZ)
+ return ZZ[1]
}
// Substitute V for x in U, where the leading term of V is zero
@@ -571,69 +570,69 @@ func Exp(U PS) PS{
// bug: a nonzero constant term is ignored
func Subst(U, V PS) PS {
- Z:= mkPS();
+ Z:= mkPS()
go func(U, V, Z PS) {
- VV := Split(V);
- <-Z.req;
- u := get(U);
- Z.dat <- u;
+ VV := Split(V)
+ <-Z.req
+ u := get(U)
+ Z.dat <- u
if end(u) == 0 {
if end(get(VV[0])) != 0 {
- put(finis,Z);
+ put(finis,Z)
} else {
- copy(Mul(VV[0],Subst(U,VV[1])),Z);
+ copy(Mul(VV[0],Subst(U,VV[1])),Z)
}
}
- }(U, V, Z);
- return Z;
+ }(U, V, Z)
+ return Z
}
// Monomial Substition: U(c x^n)
// Each Ui is multiplied by c^i and followed by n-1 zeros
func MonSubst(U PS, c0 *rat, n int) PS {
- Z:= mkPS();
+ Z:= mkPS()
go func(U, Z PS, c0 *rat, n int) {
- c := one;
+ c := one
for {
- <-Z.req;
- u := get(U);
- Z.dat <- mul(u, c);
- c = mul(c, c0);
+ <-Z.req
+ u := get(U)
+ Z.dat <- mul(u, c)
+ c = mul(c, c0)
if end(u) != 0 {
- Z.dat <- finis;
- break;
+ Z.dat <- finis
+ break
}
for i := 1; i < n; i++ {
- <-Z.req;
- Z.dat <- zero;
+ <-Z.req
+ Z.dat <- zero
}
}
- }(U, Z, c0, n);
- return Z;
+ }(U, Z, c0, n)
+ return Z
}
func Init() {
- chnameserial = -1;
- seqno = 0;
- chnames = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- zero = itor(0);
- one = itor(1);
- finis = i2tor(1,0);
- Ones = Rep(one);
- Twos = Rep(itor(2));
+ chnameserial = -1
+ seqno = 0
+ chnames = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+ zero = itor(0)
+ one = itor(1)
+ finis = i2tor(1,0)
+ Ones = Rep(one)
+ Twos = Rep(itor(2))
}
func check(U PS, c *rat, count int, str string) {
for i := 0; i < count; i++ {
- r := get(U);
+ r := get(U)
if !r.eq(c) {
- print("got: ");
- r.pr();
- print("should get ");
- c.pr();
- print("\n");
+ print("got: ")
+ r.pr()
+ print("should get ")
+ c.pr()
+ print("\n")
panic(str)
}
}
@@ -642,82 +641,82 @@ func check(U PS, c *rat, count int, str string) {
const N=10
func checka(U PS, a []*rat, str string) {
for i := 0; i < N; i++ {
- check(U, a[i], 1, str);
+ check(U, a[i], 1, str)
}
}
func main() {
- Init();
+ Init()
if len(os.Args) > 1 { // print
- print("Ones: "); Printn(Ones, 10);
- print("Twos: "); Printn(Twos, 10);
- print("Add: "); Printn(Add(Ones, Twos), 10);
- print("Diff: "); Printn(Diff(Ones), 10);
- print("Integ: "); Printn(Integ(zero, Ones), 10);
- print("CMul: "); Printn(Cmul(neg(one), Ones), 10);
- print("Sub: "); Printn(Sub(Ones, Twos), 10);
- print("Mul: "); Printn(Mul(Ones, Ones), 10);
- print("Exp: "); Printn(Exp(Ones), 15);
- print("MonSubst: "); Printn(MonSubst(Ones, neg(one), 2), 10);
- print("ATan: "); Printn(Integ(zero, MonSubst(Ones, neg(one), 2)), 10);
+ print("Ones: "); Printn(Ones, 10)
+ print("Twos: "); Printn(Twos, 10)
+ print("Add: "); Printn(Add(Ones, Twos), 10)
+ print("Diff: "); Printn(Diff(Ones), 10)
+ print("Integ: "); Printn(Integ(zero, Ones), 10)
+ print("CMul: "); Printn(Cmul(neg(one), Ones), 10)
+ print("Sub: "); Printn(Sub(Ones, Twos), 10)
+ print("Mul: "); Printn(Mul(Ones, Ones), 10)
+ print("Exp: "); Printn(Exp(Ones), 15)
+ print("MonSubst: "); Printn(MonSubst(Ones, neg(one), 2), 10)
+ print("ATan: "); Printn(Integ(zero, MonSubst(Ones, neg(one), 2)), 10)
} else { // test
- check(Ones, one, 5, "Ones");
- check(Add(Ones, Ones), itor(2), 0, "Add Ones Ones"); // 1 1 1 1 1
- check(Add(Ones, Twos), itor(3), 0, "Add Ones Twos"); // 3 3 3 3 3
- a := make([]*rat, N);
- d := Diff(Ones);
+ check(Ones, one, 5, "Ones")
+ check(Add(Ones, Ones), itor(2), 0, "Add Ones Ones") // 1 1 1 1 1
+ check(Add(Ones, Twos), itor(3), 0, "Add Ones Twos") // 3 3 3 3 3
+ a := make([]*rat, N)
+ d := Diff(Ones)
for i:=0; i < N; i++ {
a[i] = itor(int64(i+1))
}
- checka(d, a, "Diff"); // 1 2 3 4 5
- in := Integ(zero, Ones);
- a[0] = zero; // integration constant
+ checka(d, a, "Diff") // 1 2 3 4 5
+ in := Integ(zero, Ones)
+ a[0] = zero // integration constant
for i:=1; i < N; i++ {
a[i] = i2tor(1, int64(i))
}
- checka(in, a, "Integ"); // 0 1 1/2 1/3 1/4 1/5
- check(Cmul(neg(one), Twos), itor(-2), 10, "CMul"); // -1 -1 -1 -1 -1
- check(Sub(Ones, Twos), itor(-1), 0, "Sub Ones Twos"); // -1 -1 -1 -1 -1
- m := Mul(Ones, Ones);
+ checka(in, a, "Integ") // 0 1 1/2 1/3 1/4 1/5
+ check(Cmul(neg(one), Twos), itor(-2), 10, "CMul") // -1 -1 -1 -1 -1
+ check(Sub(Ones, Twos), itor(-1), 0, "Sub Ones Twos") // -1 -1 -1 -1 -1
+ m := Mul(Ones, Ones)
for i:=0; i < N; i++ {
a[i] = itor(int64(i+1))
}
- checka(m, a, "Mul"); // 1 2 3 4 5
- e := Exp(Ones);
- a[0] = itor(1);
- a[1] = itor(1);
- a[2] = i2tor(3,2);
- a[3] = i2tor(13,6);
- a[4] = i2tor(73,24);
- a[5] = i2tor(167,40);
- a[6] = i2tor(4051,720);
- a[7] = i2tor(37633,5040);
- a[8] = i2tor(43817,4480);
- a[9] = i2tor(4596553,362880);
- checka(e, a, "Exp"); // 1 1 3/2 13/6 73/24
- at := Integ(zero, MonSubst(Ones, neg(one), 2));
+ checka(m, a, "Mul") // 1 2 3 4 5
+ e := Exp(Ones)
+ a[0] = itor(1)
+ a[1] = itor(1)
+ a[2] = i2tor(3,2)
+ a[3] = i2tor(13,6)
+ a[4] = i2tor(73,24)
+ a[5] = i2tor(167,40)
+ a[6] = i2tor(4051,720)
+ a[7] = i2tor(37633,5040)
+ a[8] = i2tor(43817,4480)
+ a[9] = i2tor(4596553,362880)
+ checka(e, a, "Exp") // 1 1 3/2 13/6 73/24
+ at := Integ(zero, MonSubst(Ones, neg(one), 2))
for c, i := 1, 0; i < N; i++ {
if i%2 == 0 {
a[i] = zero
} else {
- a[i] = i2tor(int64(c), int64(i));
+ a[i] = i2tor(int64(c), int64(i))
c *= -1
}
}
checka(at, a, "ATan"); // 0 -1 0 -1/3 0 -1/5
/*
- t := Revert(Integ(zero, MonSubst(Ones, neg(one), 2)));
- a[0] = zero;
- a[1] = itor(1);
- a[2] = zero;
- a[3] = i2tor(1,3);
- a[4] = zero;
- a[5] = i2tor(2,15);
- a[6] = zero;
- a[7] = i2tor(17,315);
- a[8] = zero;
- a[9] = i2tor(62,2835);
- checka(t, a, "Tan"); // 0 1 0 1/3 0 2/15
+ t := Revert(Integ(zero, MonSubst(Ones, neg(one), 2)))
+ a[0] = zero
+ a[1] = itor(1)
+ a[2] = zero
+ a[3] = i2tor(1,3)
+ a[4] = zero
+ a[5] = i2tor(2,15)
+ a[6] = zero
+ a[7] = i2tor(17,315)
+ a[8] = zero
+ a[9] = i2tor(62,2835)
+ checka(t, a, "Tan") // 0 1 0 1/3 0 2/15
*/
}
}
diff --git a/test/chan/select3.go b/test/chan/select3.go
new file mode 100644
index 000000000..a1a2ef50b
--- /dev/null
+++ b/test/chan/select3.go
@@ -0,0 +1,203 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+// Tests verifying the semantics of the select statement
+// for basic empty/non-empty cases.
+
+package main
+
+import "time"
+
+const always = "function did not"
+const never = "function did"
+
+
+func unreachable() {
+ panic("control flow shouldn't reach here")
+}
+
+
+// Calls f and verifies that f always/never panics depending on signal.
+func testPanic(signal string, f func()) {
+ defer func() {
+ s := never
+ if recover() != nil {
+ s = always // f panicked
+ }
+ if s != signal {
+ panic(signal + " panic")
+ }
+ }()
+ f()
+}
+
+
+// Calls f and empirically verifies that f always/never blocks depending on signal.
+func testBlock(signal string, f func()) {
+ c := make(chan string)
+ go func() {
+ f()
+ c <- never // f didn't block
+ }()
+ go func() {
+ time.Sleep(1e8) // 0.1s seems plenty long
+ c <- always // f blocked always
+ }()
+ if <-c != signal {
+ panic(signal + " block")
+ }
+}
+
+
+func main() {
+ const async = 1 // asynchronous channels
+ var nilch chan int
+ closedch := make(chan int)
+ close(closedch)
+
+ // sending/receiving from a nil channel outside a select panics
+ testPanic(always, func() {
+ nilch <- 7
+ })
+ testPanic(always, func() {
+ <-nilch
+ })
+
+ // sending/receiving from a nil channel inside a select never panics
+ testPanic(never, func() {
+ select {
+ case nilch <- 7:
+ unreachable()
+ default:
+ }
+ })
+ testPanic(never, func() {
+ select {
+ case <-nilch:
+ unreachable()
+ default:
+ }
+ })
+
+ // sending to an async channel with free buffer space never blocks
+ testBlock(never, func() {
+ ch := make(chan int, async)
+ ch <- 7
+ })
+
+ // receiving (a small number of times) from a closed channel never blocks
+ testBlock(never, func() {
+ for i := 0; i < 10; i++ {
+ if <-closedch != 0 {
+ panic("expected zero value when reading from closed channel")
+ }
+ }
+ })
+
+ // sending (a small number of times) to a closed channel is not specified
+ // but the current implementation doesn't block: test that different
+ // implementations behave the same
+ testBlock(never, func() {
+ for i := 0; i < 10; i++ {
+ closedch <- 7
+ }
+ })
+
+ // receiving from a non-ready channel always blocks
+ testBlock(always, func() {
+ ch := make(chan int)
+ <-ch
+ })
+
+ // empty selects always block
+ testBlock(always, func() {
+ select {
+ }
+ })
+
+ // selects with only nil channels always block
+ testBlock(always, func() {
+ select {
+ case <-nilch:
+ unreachable()
+ }
+ })
+ testBlock(always, func() {
+ select {
+ case nilch <- 7:
+ unreachable()
+ }
+ })
+ testBlock(always, func() {
+ select {
+ case <-nilch:
+ unreachable()
+ case nilch <- 7:
+ unreachable()
+ }
+ })
+
+ // selects with non-ready non-nil channels always block
+ testBlock(always, func() {
+ ch := make(chan int)
+ select {
+ case <-ch:
+ unreachable()
+ }
+ })
+
+ // selects with default cases don't block
+ testBlock(never, func() {
+ select {
+ default:
+ }
+ })
+ testBlock(never, func() {
+ select {
+ case <-nilch:
+ unreachable()
+ default:
+ }
+ })
+ testBlock(never, func() {
+ select {
+ case nilch <- 7:
+ unreachable()
+ default:
+ }
+ })
+
+ // selects with ready channels don't block
+ testBlock(never, func() {
+ ch := make(chan int, async)
+ select {
+ case ch <- 7:
+ default:
+ unreachable()
+ }
+ })
+ testBlock(never, func() {
+ ch := make(chan int, async)
+ ch <- 7
+ select {
+ case <-ch:
+ default:
+ unreachable()
+ }
+ })
+
+ // selects with closed channels don't block
+ testBlock(never, func() {
+ select {
+ case <-closedch:
+ }
+ })
+ testBlock(never, func() {
+ select {
+ case closedch <- 7:
+ }
+ })
+}
diff --git a/test/chan/select4.go b/test/chan/select4.go
new file mode 100644
index 000000000..46618ac88
--- /dev/null
+++ b/test/chan/select4.go
@@ -0,0 +1,25 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+package main
+
+func f() *int {
+ println("BUG: called f")
+ return new(int)
+}
+
+func main() {
+ var x struct {
+ a int
+ }
+ c := make(chan int, 1)
+ c1 := make(chan int)
+ c <- 42
+ select {
+ case *f() = <-c1:
+ // nothing
+ case x.a = <-c:
+ if x.a != 42 {
+ println("BUG:", x.a)
+ }
+ }
+}
diff --git a/test/char_lit.go b/test/char_lit.go
index e4f3f8323..99be77a57 100644
--- a/test/char_lit.go
+++ b/test/char_lit.go
@@ -32,13 +32,12 @@ func main() {
'\ubabe' +
'\U0010FFFF' +
'\U000ebabe'
- ;
if '\U000ebabe' != 0x000ebabe {
- print("ebabe wrong\n");
+ print("ebabe wrong\n")
os.Exit(1)
}
if i != 0x20e213 {
- print("number is ", i, " should be ", 0x20e213, "\n");
+ print("number is ", i, " should be ", 0x20e213, "\n")
os.Exit(1)
- }
+ }
}
diff --git a/test/char_lit1.go b/test/char_lit1.go
index ccf1cc9fc..dc5385291 100644
--- a/test/char_lit1.go
+++ b/test/char_lit1.go
@@ -10,16 +10,16 @@ const (
// check that surrogate pair elements are invalid
// (d800-dbff, dc00-dfff).
_ = '\ud7ff' // ok
- _ = '\ud800' // ERROR "Unicode"
- _ = "\U0000D999" // ERROR "Unicode"
- _ = '\udc01' // ERROR "Unicode"
- _ = '\U0000dddd' // ERROR "Unicode"
- _ = '\udfff' // ERROR "Unicode"
+ _ = '\ud800' // ERROR "Unicode|unicode"
+ _ = "\U0000D999" // ERROR "Unicode|unicode"
+ _ = '\udc01' // ERROR "Unicode|unicode"
+ _ = '\U0000dddd' // ERROR "Unicode|unicode"
+ _ = '\udfff' // ERROR "Unicode|unicode"
_ = '\ue000' // ok
_ = '\U0010ffff' // ok
- _ = '\U00110000' // ERROR "Unicode"
+ _ = '\U00110000' // ERROR "Unicode|unicode"
_ = "abc\U0010ffffdef" // ok
- _ = "abc\U00110000def" // ERROR "Unicode"
- _ = '\Uffffffff' // ERROR "Unicode"
+ _ = "abc\U00110000def" // ERROR "Unicode|unicode"
+ _ = '\Uffffffff' // ERROR "Unicode|unicode"
)
diff --git a/test/closedchan.go b/test/closedchan.go
index 4ab12c775..c7c759be3 100644
--- a/test/closedchan.go
+++ b/test/closedchan.go
@@ -12,13 +12,13 @@
package main
type Chan interface {
- Send(int);
- Nbsend(int) bool;
- Recv() int;
- Nbrecv() (int, bool);
- Close();
- Closed() bool;
- Impl() string;
+ Send(int)
+ Nbsend(int) bool
+ Recv() int
+ Nbrecv() (int, bool)
+ Close()
+ Closed() bool
+ Impl() string
}
// direct channel operations
@@ -28,7 +28,7 @@ func (c XChan) Send(x int) {
}
func (c XChan) Nbsend(x int) bool {
- return c <- x;
+ return c <- x
}
func (c XChan) Recv() int {
@@ -36,8 +36,8 @@ func (c XChan) Recv() int {
}
func (c XChan) Nbrecv() (int, bool) {
- x, ok := <-c;
- return x, ok;
+ x, ok := <-c
+ return x, ok
}
func (c XChan) Close() {
@@ -63,29 +63,29 @@ func (c SChan) Send(x int) {
func (c SChan) Nbsend(x int) bool {
select {
case c <- x:
- return true;
+ return true
default:
- return false;
+ return false
}
- panic("nbsend");
+ panic("nbsend")
}
func (c SChan) Recv() int {
select {
case x := <-c:
- return x;
+ return x
}
- panic("recv");
+ panic("recv")
}
func (c SChan) Nbrecv() (int, bool) {
select {
case x := <-c:
- return x, true;
+ return x, true
default:
- return 0, false;
+ return 0, false
}
- panic("nbrecv");
+ panic("nbrecv")
}
func (c SChan) Close() {
@@ -97,101 +97,101 @@ func (c SChan) Closed() bool {
}
func (c SChan) Impl() string {
- return "(select)";
+ return "(select)"
}
func test1(c Chan) {
// not closed until the close signal (a zero value) has been received.
if c.Closed() {
- println("test1: Closed before Recv zero:", c.Impl());
+ println("test1: Closed before Recv zero:", c.Impl())
}
for i := 0; i < 3; i++ {
// recv a close signal (a zero value)
if x := c.Recv(); x != 0 {
- println("test1: recv on closed got non-zero:", x, c.Impl());
+ println("test1: recv on closed got non-zero:", x, c.Impl())
}
// should now be closed.
if !c.Closed() {
- println("test1: not closed after recv zero", c.Impl());
+ println("test1: not closed after recv zero", c.Impl())
}
// should work with ,ok: received a value without blocking, so ok == true.
- x, ok := c.Nbrecv();
+ x, ok := c.Nbrecv()
if !ok {
- println("test1: recv on closed got not ok", c.Impl());
+ println("test1: recv on closed got not ok", c.Impl())
}
if x != 0 {
- println("test1: recv ,ok on closed got non-zero:", x, c.Impl());
+ println("test1: recv ,ok on closed got non-zero:", x, c.Impl())
}
}
// send should work with ,ok too: sent a value without blocking, so ok == true.
- ok := c.Nbsend(1);
+ ok := c.Nbsend(1)
if !ok {
- println("test1: send on closed got not ok", c.Impl());
+ println("test1: send on closed got not ok", c.Impl())
}
// but the value should have been discarded.
if x := c.Recv(); x != 0 {
- println("test1: recv on closed got non-zero after send on closed:", x, c.Impl());
+ println("test1: recv on closed got non-zero after send on closed:", x, c.Impl())
}
// similarly Send.
- c.Send(2);
+ c.Send(2)
if x := c.Recv(); x != 0 {
- println("test1: recv on closed got non-zero after send on closed:", x, c.Impl());
+ println("test1: recv on closed got non-zero after send on closed:", x, c.Impl())
}
}
func testasync1(c Chan) {
// not closed until the close signal (a zero value) has been received.
if c.Closed() {
- println("testasync1: Closed before Recv zero:", c.Impl());
+ println("testasync1: Closed before Recv zero:", c.Impl())
}
// should be able to get the last value via Recv
if x := c.Recv(); x != 1 {
- println("testasync1: Recv did not get 1:", x, c.Impl());
+ println("testasync1: Recv did not get 1:", x, c.Impl())
}
- test1(c);
+ test1(c)
}
func testasync2(c Chan) {
// not closed until the close signal (a zero value) has been received.
if c.Closed() {
- println("testasync2: Closed before Recv zero:", c.Impl());
+ println("testasync2: Closed before Recv zero:", c.Impl())
}
// should be able to get the last value via Nbrecv
if x, ok := c.Nbrecv(); !ok || x != 1 {
- println("testasync2: Nbrecv did not get 1, true:", x, ok, c.Impl());
+ println("testasync2: Nbrecv did not get 1, true:", x, ok, c.Impl())
}
- test1(c);
+ test1(c)
}
func closedsync() chan int {
- c := make(chan int);
- close(c);
- return c;
+ c := make(chan int)
+ close(c)
+ return c
}
func closedasync() chan int {
- c := make(chan int, 2);
- c <- 1;
- close(c);
- return c;
+ c := make(chan int, 2)
+ c <- 1
+ close(c)
+ return c
}
func main() {
- test1(XChan(closedsync()));
- test1(SChan(closedsync()));
+ test1(XChan(closedsync()))
+ test1(SChan(closedsync()))
- testasync1(XChan(closedasync()));
- testasync1(SChan(closedasync()));
- testasync2(XChan(closedasync()));
- testasync2(SChan(closedasync()));
+ testasync1(XChan(closedasync()))
+ testasync1(SChan(closedasync()))
+ testasync2(XChan(closedasync()))
+ testasync2(SChan(closedasync()))
}
diff --git a/test/closure.go b/test/closure.go
index 54e4cf8ea..3033c02ed 100644
--- a/test/closure.go
+++ b/test/closure.go
@@ -98,4 +98,15 @@ func main() {
println("newfunc returned broken funcs")
panic("fail")
}
+
+ ff(1)
+}
+
+func ff(x int) {
+ call(func() {
+ _ = x
+ })
+}
+
+func call(func()) {
}
diff --git a/test/cmp1.go b/test/cmp1.go
index db0a486dd..698544c58 100644
--- a/test/cmp1.go
+++ b/test/cmp1.go
@@ -26,6 +26,8 @@ func istrue(b bool) {
}
}
+type T *int
+
func main() {
var a []int
var b map[string]int
@@ -55,6 +57,24 @@ func main() {
isfalse(ib == id)
istrue(ic == id)
istrue(ie == ie)
+
+ // these are okay because one side of the
+ // comparison need only be assignable to the other.
+ isfalse(a == ib)
+ isfalse(a == ic)
+ isfalse(a == id)
+ isfalse(b == ic)
+ isfalse(b == id)
+ istrue(c == id)
+ istrue(e == ie)
+
+ isfalse(ia == b)
+ isfalse(ia == c)
+ isfalse(ia == d)
+ isfalse(ib == c)
+ isfalse(ib == d)
+ istrue(ic == d)
+ istrue(ie == e)
// 6g used to let this go through as true.
var g uint64 = 123
@@ -73,4 +93,38 @@ func main() {
println("m[ic] = ", m[ic])
panic("bad m[ic]")
}
+
+ // non-interface comparisons
+ {
+ c := make(chan int)
+ c1 := (<-chan int)(c)
+ c2 := (chan<- int)(c)
+ istrue(c == c1)
+ istrue(c == c2)
+ istrue(c1 == c)
+ istrue(c2 == c)
+
+ d := make(chan int)
+ isfalse(c == d)
+ isfalse(d == c)
+ isfalse(d == c1)
+ isfalse(d == c2)
+ isfalse(c1 == d)
+ isfalse(c2 == d)
+ }
+
+ // named types vs not
+ {
+ var x = new(int)
+ var y T
+ var z T = x
+
+ isfalse(x == y)
+ istrue(x == z)
+ isfalse(y == z)
+
+ isfalse(y == x)
+ istrue(z == x)
+ isfalse(z == y)
+ }
}
diff --git a/test/cmp2.go b/test/cmp2.go
index 5442fa17a..f6f124f2e 100644
--- a/test/cmp2.go
+++ b/test/cmp2.go
@@ -9,7 +9,7 @@ package main
func use(bool) { }
func main() {
- var a []int;
- var ia interface{} = a;
- use(ia == ia);
+ var a []int
+ var ia interface{} = a
+ use(ia == ia)
}
diff --git a/test/cmp3.go b/test/cmp3.go
index f34542ade..dd90bfb03 100644
--- a/test/cmp3.go
+++ b/test/cmp3.go
@@ -9,7 +9,7 @@ package main
func use(bool) { }
func main() {
- var b []int;
- var ib interface{} = b;
- use(ib == ib);
+ var b []int
+ var ib interface{} = b
+ use(ib == ib)
}
diff --git a/test/cmp4.go b/test/cmp4.go
index ca1ad2ad3..3f9b2c0b8 100644
--- a/test/cmp4.go
+++ b/test/cmp4.go
@@ -7,8 +7,8 @@
package main
func main() {
- var a []int;
- var ia interface{} = a;
- var m = make(map[interface{}] int);
- m[ia] = 1;
+ var a []int
+ var ia interface{} = a
+ var m = make(map[interface{}] int)
+ m[ia] = 1
}
diff --git a/test/cmp5.go b/test/cmp5.go
index 9c339a43a..3a7d733f0 100644
--- a/test/cmp5.go
+++ b/test/cmp5.go
@@ -7,8 +7,8 @@
package main
func main() {
- var b []int;
- var ib interface{} = b;
- var m = make(map[interface{}] int);
- m[ib] = 1;
+ var b []int
+ var ib interface{} = b
+ var m = make(map[interface{}] int)
+ m[ib] = 1
}
diff --git a/test/cmp6.go b/test/cmp6.go
new file mode 100644
index 000000000..981a85953
--- /dev/null
+++ b/test/cmp6.go
@@ -0,0 +1,42 @@
+// errchk $G -e $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.
+
+package main
+
+func use(bool) {}
+
+type T1 *int
+type T2 *int
+
+func main() {
+ // Arguments to comparison must be
+ // assignable one to the other (or vice versa)
+ // so chan int can be compared against
+ // directional channels but channel of different
+ // direction cannot be compared against each other.
+ var c1 chan <-int
+ var c2 <-chan int
+ var c3 chan int
+
+ use(c1 == c2) // ERROR "invalid operation"
+ use(c2 == c1) // ERROR "invalid operation"
+ use(c1 == c3)
+ use(c2 == c2)
+ use(c3 == c1)
+ use(c3 == c2)
+
+ // Same applies to named types.
+ var p1 T1
+ var p2 T2
+ var p3 *int
+
+ use(p1 == p2) // ERROR "invalid operation"
+ use(p2 == p1) // ERROR "invalid operation"
+ use(p1 == p3)
+ use(p2 == p2)
+ use(p3 == p1)
+ use(p3 == p2)
+}
diff --git a/test/cmplx.go b/test/cmplx.go
index 6262c682d..fad96c605 100644
--- a/test/cmplx.go
+++ b/test/cmplx.go
@@ -22,6 +22,7 @@ func main() {
c64 = cmplx(f32, f32)
c128 = cmplx(f64, f64)
+ _ = complex(0) // ok
_ = cmplx(f, f32) // ERROR "cmplx"
_ = cmplx(f, f64) // ERROR "cmplx"
_ = cmplx(f32, f) // ERROR "cmplx"
diff --git a/test/cmplxdivide.go b/test/cmplxdivide.go
index ac4730d64..6a67b175d 100644
--- a/test/cmplxdivide.go
+++ b/test/cmplxdivide.go
@@ -34,9 +34,14 @@ func calike(a, b complex128) bool {
}
func main() {
+ bad := false
for _, t := range tests {
x := t.f/t.g
if !calike(x, t.out) {
+ if !bad {
+ fmt.Printf("BUG\n")
+ bad = true
+ }
fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x)
}
}
diff --git a/test/complit.go b/test/complit.go
index 3d5a68469..f3b7c9abe 100644
--- a/test/complit.go
+++ b/test/complit.go
@@ -11,9 +11,9 @@ type T struct { i int; f float; s string; next *T }
type R struct { num int }
func itor(a int) *R {
- r := new(R);
- r.num = a;
- return r;
+ r := new(R)
+ r.num = a
+ return r
}
func eq(a []*R) {
@@ -22,49 +22,49 @@ func eq(a []*R) {
}
}
-type P struct { a, b int };
+type P struct { a, b int }
func NewP(a, b int) *P {
return &P{a, b}
}
func main() {
- var t T;
- t = T{0, 7.2, "hi", &t};
+ var t T
+ t = T{0, 7.2, "hi", &t}
- var tp *T;
- tp = &T{0, 7.2, "hi", &t};
+ var tp *T
+ tp = &T{0, 7.2, "hi", &t}
- a1 := []int{1,2,3};
+ a1 := []int{1,2,3}
if len(a1) != 3 { panic("a1") }
- a2 := [10]int{1,2,3};
+ a2 := [10]int{1,2,3}
if len(a2) != 10 || cap(a2) != 10 { panic("a2") }
- a3 := [10]int{1,2,3,};
+ a3 := [10]int{1,2,3,}
if len(a3) != 10 || a2[3] != 0 { panic("a3") }
- var oai []int;
- oai = []int{1,2,3};
+ var oai []int
+ oai = []int{1,2,3}
if len(oai) != 3 { panic("oai") }
- at := [...]*T{&t, tp, &t};
+ at := [...]*T{&t, tp, &t}
if len(at) != 3 { panic("at") }
- c := make(chan int);
- ac := []chan int{c, c, c};
+ c := make(chan int)
+ ac := []chan int{c, c, c}
if len(ac) != 3 { panic("ac") }
- aat := [][len(at)]*T{at, at};
+ aat := [][len(at)]*T{at, at}
if len(aat) != 2 || len(aat[1]) != 3 { panic("aat") }
- s := string([]byte{'h', 'e', 'l', 'l', 'o'});
+ s := string([]byte{'h', 'e', 'l', 'l', 'o'})
if s != "hello" { panic("s") }
- m := map[string]float{"one":1.0, "two":2.0, "pi":22./7.};
+ m := map[string]float{"one":1.0, "two":2.0, "pi":22./7.}
if len(m) != 3 { panic("m") }
- eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)});
+ eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)})
- p1 := NewP(1, 2);
- p2 := NewP(1, 2);
+ p1 := NewP(1, 2)
+ p2 := NewP(1, 2)
if p1 == p2 { panic("NewP") }
}
diff --git a/test/compos.go b/test/compos.go
index 78a7965ef..70f90f379 100644
--- a/test/compos.go
+++ b/test/compos.go
@@ -7,7 +7,7 @@
package main
type T struct {
- int;
+ int
}
func f() *T {
@@ -15,9 +15,9 @@ func f() *T {
}
func main() {
- x := f();
- y := f();
+ x := f()
+ y := f()
if x == y {
- panic("not allocating & composite literals");
+ panic("not allocating & composite literals")
}
}
diff --git a/test/const.go b/test/const.go
index 8e587cfe5..a55e13a40 100644
--- a/test/const.go
+++ b/test/const.go
@@ -7,26 +7,26 @@
package main
const (
- c0 = 0;
- cm1 = -1;
- chuge = 1 << 100;
- chuge_1 = chuge - 1;
- c1 = chuge >> 100;
- c3div2 = 3/2;
- c1e3 = 1e3;
+ c0 = 0
+ cm1 = -1
+ chuge = 1 << 100
+ chuge_1 = chuge - 1
+ c1 = chuge >> 100
+ c3div2 = 3/2
+ c1e3 = 1e3
- ctrue = true;
- cfalse = !ctrue;
+ ctrue = true
+ cfalse = !ctrue
)
const (
- f0 = 0.0;
- fm1 = -1.;
- fhuge float64 = 1 << 100;
- fhuge_1 float64 = chuge - 1;
- f1 float64 = chuge >> 100;
- f3div2 = 3./2.;
- f1e3 float64 = 1e3;
+ f0 = 0.0
+ fm1 = -1.
+ fhuge float64 = 1 << 100
+ fhuge_1 float64 = chuge - 1
+ f1 float64 = chuge >> 100
+ f3div2 = 3./2.
+ f1e3 float64 = 1e3
)
func assert(t bool, s string) {
@@ -36,85 +36,85 @@ func assert(t bool, s string) {
}
func ints() {
- assert(c0 == 0, "c0");
- assert(c1 == 1, "c1");
- assert(chuge > chuge_1, "chuge");
- assert(chuge_1 + 1 == chuge, "chuge 1");
- assert(chuge + cm1 +1 == chuge, "cm1");
- assert(c3div2 == 1, "3/2");
- assert(c1e3 == 1000, "c1e3 int");
- assert(c1e3 == 1e3, "c1e3 float");
+ assert(c0 == 0, "c0")
+ assert(c1 == 1, "c1")
+ assert(chuge > chuge_1, "chuge")
+ assert(chuge_1 + 1 == chuge, "chuge 1")
+ assert(chuge + cm1 +1 == chuge, "cm1")
+ assert(c3div2 == 1, "3/2")
+ assert(c1e3 == 1000, "c1e3 int")
+ assert(c1e3 == 1e3, "c1e3 float")
// verify that all (in range) are assignable as ints
- var i int;
- i = c0;
- assert(i == c0, "i == c0");
- i = cm1;
- assert(i == cm1, "i == cm1");
- i = c1;
- assert(i == c1, "i == c1");
- i = c3div2;
- assert(i == c3div2, "i == c3div2");
- i = c1e3;
- assert(i == c1e3, "i == c1e3");
+ var i int
+ i = c0
+ assert(i == c0, "i == c0")
+ i = cm1
+ assert(i == cm1, "i == cm1")
+ i = c1
+ assert(i == c1, "i == c1")
+ i = c3div2
+ assert(i == c3div2, "i == c3div2")
+ i = c1e3
+ assert(i == c1e3, "i == c1e3")
// verify that all are assignable as floats
- var f float64;
- f = c0;
- assert(f == c0, "f == c0");
- f = cm1;
- assert(f == cm1, "f == cm1");
- f = chuge;
- assert(f == chuge, "f == chuge");
- f = chuge_1;
- assert(f == chuge_1, "f == chuge_1");
- f = c1;
- assert(f == c1, "f == c1");
- f = c3div2;
- assert(f == c3div2, "f == c3div2");
- f = c1e3;
- assert(f == c1e3, "f == c1e3");
+ var f float64
+ f = c0
+ assert(f == c0, "f == c0")
+ f = cm1
+ assert(f == cm1, "f == cm1")
+ f = chuge
+ assert(f == chuge, "f == chuge")
+ f = chuge_1
+ assert(f == chuge_1, "f == chuge_1")
+ f = c1
+ assert(f == c1, "f == c1")
+ f = c3div2
+ assert(f == c3div2, "f == c3div2")
+ f = c1e3
+ assert(f == c1e3, "f == c1e3")
}
func floats() {
- assert(f0 == c0, "f0");
- assert(f1 == c1, "f1");
- assert(fhuge == fhuge_1, "fhuge"); // float64 can't distinguish fhuge, fhuge_1.
- assert(fhuge_1 + 1 == fhuge, "fhuge 1");
- assert(fhuge + fm1 +1 == fhuge, "fm1");
- assert(f3div2 == 1.5, "3./2.");
- assert(f1e3 == 1000, "f1e3 int");
- assert(f1e3 == 1.e3, "f1e3 float");
+ assert(f0 == c0, "f0")
+ assert(f1 == c1, "f1")
+ assert(fhuge == fhuge_1, "fhuge") // float64 can't distinguish fhuge, fhuge_1.
+ assert(fhuge_1 + 1 == fhuge, "fhuge 1")
+ assert(fhuge + fm1 +1 == fhuge, "fm1")
+ assert(f3div2 == 1.5, "3./2.")
+ assert(f1e3 == 1000, "f1e3 int")
+ assert(f1e3 == 1.e3, "f1e3 float")
// verify that all (in range) are assignable as ints
- var i int;
- i = f0;
- assert(i == f0, "i == f0");
- i = fm1;
- assert(i == fm1, "i == fm1");
+ var i int
+ i = f0
+ assert(i == f0, "i == f0")
+ i = fm1
+ assert(i == fm1, "i == fm1")
// verify that all are assignable as floats
- var f float64;
- f = f0;
- assert(f == f0, "f == f0");
- f = fm1;
- assert(f == fm1, "f == fm1");
- f = fhuge;
- assert(f == fhuge, "f == fhuge");
- f = fhuge_1;
- assert(f == fhuge_1, "f == fhuge_1");
- f = f1;
- assert(f == f1, "f == f1");
- f = f3div2;
- assert(f == f3div2, "f == f3div2");
- f = f1e3;
- assert(f == f1e3, "f == f1e3");
+ var f float64
+ f = f0
+ assert(f == f0, "f == f0")
+ f = fm1
+ assert(f == fm1, "f == fm1")
+ f = fhuge
+ assert(f == fhuge, "f == fhuge")
+ f = fhuge_1
+ assert(f == fhuge_1, "f == fhuge_1")
+ f = f1
+ assert(f == f1, "f == f1")
+ f = f3div2
+ assert(f == f3div2, "f == f3div2")
+ f = f1e3
+ assert(f == f1e3, "f == f1e3")
}
func main() {
- ints();
- floats();
+ ints()
+ floats()
- assert(ctrue == true, "ctrue == true");
- assert(cfalse == false, "cfalse == false");
+ assert(ctrue == true, "ctrue == true")
+ assert(cfalse == false, "cfalse == false")
}
diff --git a/test/const1.go b/test/const1.go
index 78fb1f4e2..cf07055cf 100644
--- a/test/const1.go
+++ b/test/const1.go
@@ -9,71 +9,73 @@ package main
type I interface {}
const (
// assume all types behave similarly to int8/uint8
- Int8 int8 = 101;
- Minus1 int8 = -1;
- Uint8 uint8 = 102;
- Const = 103;
+ Int8 int8 = 101
+ Minus1 int8 = -1
+ Uint8 uint8 = 102
+ Const = 103
- Float32 float32 = 104.5;
- Float float = 105.5;
- ConstFloat = 106.5;
- Big float64 = 1e300;
+ Float32 float32 = 104.5
+ Float float = 105.5
+ ConstFloat = 106.5
+ Big float64 = 1e300
- String = "abc";
- Bool = true;
+ String = "abc"
+ Bool = true
)
var (
- a1 = Int8 * 100; // ERROR "overflow"
- a2 = Int8 * -1; // OK
- a3 = Int8 * 1000; // ERROR "overflow"
- a4 = Int8 * int8(1000); // ERROR "overflow"
- a5 = int8(Int8 * 1000); // ERROR "overflow"
- a6 = int8(Int8 * int8(1000)); // ERROR "overflow"
- a7 = Int8 - 2*Int8 - 2*Int8; // ERROR "overflow"
- a8 = Int8 * Const / 100; // ERROR "overflow"
- a9 = Int8 * (Const / 100); // OK
+ a1 = Int8 * 100 // ERROR "overflow"
+ a2 = Int8 * -1 // OK
+ a3 = Int8 * 1000 // ERROR "overflow"
+ a4 = Int8 * int8(1000) // ERROR "overflow"
+ a5 = int8(Int8 * 1000) // ERROR "overflow"
+ a6 = int8(Int8 * int8(1000)) // ERROR "overflow"
+ a7 = Int8 - 2*Int8 - 2*Int8 // ERROR "overflow"
+ a8 = Int8 * Const / 100 // ERROR "overflow"
+ a9 = Int8 * (Const / 100) // OK
- b1 = Uint8 * Uint8; // ERROR "overflow"
- b2 = Uint8 * -1; // ERROR "overflow"
- b3 = Uint8 - Uint8; // OK
- b4 = Uint8 - Uint8 - Uint8; // ERROR "overflow"
- b5 = uint8(^0); // ERROR "overflow"
- b6 = ^uint8(0); // OK
- b7 = uint8(Minus1); // ERROR "overflow"
- b8 = uint8(int8(-1)); // ERROR "overflow"
- b8a = uint8(-1); // ERROR "overflow"
- b9 byte = (1<<10) >> 8; // OK
- b10 byte = (1<<10); // ERROR "overflow"
- b11 byte = (byte(1)<<10) >> 8; // ERROR "overflow"
- b12 byte = 1000; // ERROR "overflow"
- b13 byte = byte(1000); // ERROR "overflow"
- b14 byte = byte(100) * byte(100); // ERROR "overflow"
- b15 byte = byte(100) * 100; // ERROR "overflow"
- b16 byte = byte(0) * 1000; // ERROR "overflow"
- b16a byte = 0 * 1000; // OK
- b17 byte = byte(0) * byte(1000); // ERROR "overflow"
- b18 byte = Uint8/0; // ERROR "division by zero"
+ b1 = Uint8 * Uint8 // ERROR "overflow"
+ b2 = Uint8 * -1 // ERROR "overflow"
+ b3 = Uint8 - Uint8 // OK
+ b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
+ b5 = uint8(^0) // ERROR "overflow"
+ b6 = ^uint8(0) // OK
+ b7 = uint8(Minus1) // ERROR "overflow"
+ b8 = uint8(int8(-1)) // ERROR "overflow"
+ b8a = uint8(-1) // ERROR "overflow"
+ b9 byte = (1<<10) >> 8 // OK
+ b10 byte = (1<<10) // ERROR "overflow"
+ b11 byte = (byte(1)<<10) >> 8 // ERROR "overflow"
+ b12 byte = 1000 // ERROR "overflow"
+ b13 byte = byte(1000) // ERROR "overflow"
+ b14 byte = byte(100) * byte(100) // ERROR "overflow"
+ b15 byte = byte(100) * 100 // ERROR "overflow"
+ b16 byte = byte(0) * 1000 // ERROR "overflow"
+ b16a byte = 0 * 1000 // OK
+ b17 byte = byte(0) * byte(1000) // ERROR "overflow"
+ b18 byte = Uint8/0 // ERROR "division by zero"
- c1 float64 = Big;
- c2 float64 = Big*Big; // ERROR "overflow"
- c3 float64 = float64(Big)*Big; // ERROR "overflow"
- c4 = Big*Big; // ERROR "overflow"
- c5 = Big/0; // ERROR "division by zero"
+ c1 float64 = Big
+ c2 float64 = Big*Big // ERROR "overflow"
+ c3 float64 = float64(Big)*Big // ERROR "overflow"
+ c4 = Big*Big // ERROR "overflow"
+ c5 = Big/0 // ERROR "division by zero"
)
-func f(int);
+func f(int)
func main() {
- f(Int8); // ERROR "convert|wrong type|cannot"
- f(Minus1); // ERROR "convert|wrong type|cannot"
- f(Uint8); // ERROR "convert|wrong type|cannot"
- f(Const); // OK
- f(Float32); // ERROR "convert|wrong type|cannot"
- f(Float); // ERROR "convert|wrong type|cannot"
- f(ConstFloat); // ERROR "truncate"
- f(ConstFloat - 0.5); // OK
- f(Big); // ERROR "convert|wrong type|cannot"
- f(String); // ERROR "convert|wrong type|cannot|incompatible"
- f(Bool); // ERROR "convert|wrong type|cannot|incompatible"
+ f(Int8) // ERROR "convert|wrong type|cannot"
+ f(Minus1) // ERROR "convert|wrong type|cannot"
+ f(Uint8) // ERROR "convert|wrong type|cannot"
+ f(Const) // OK
+ f(Float32) // ERROR "convert|wrong type|cannot"
+ f(Float) // ERROR "convert|wrong type|cannot"
+ f(ConstFloat) // ERROR "truncate"
+ f(ConstFloat - 0.5) // OK
+ f(Big) // ERROR "convert|wrong type|cannot"
+ f(String) // ERROR "convert|wrong type|cannot|incompatible"
+ f(Bool) // ERROR "convert|wrong type|cannot|incompatible"
}
+
+const ptr = nil // ERROR "const.*nil"
diff --git a/test/const2.go b/test/const2.go
index 2ff71ee23..bea1b9912 100644
--- a/test/const2.go
+++ b/test/const2.go
@@ -7,6 +7,6 @@
package main
const (
- A int = 1;
+ A int = 1
B byte; // ERROR "type without expr|expected .=."
)
diff --git a/test/const3.go b/test/const3.go
index dd5c88958..9bba6ced0 100644
--- a/test/const3.go
+++ b/test/const3.go
@@ -26,4 +26,10 @@ func main() {
println("type info didn't propagate in const: got", s)
panic("fail")
}
+ x := uint(5)
+ y := float64(uint64(1)<<x) // used to fail to compile
+ if y != 32 {
+ println("wrong y", y)
+ panic("fail")
+ }
}
diff --git a/test/convert3.go b/test/convert3.go
index 5f1f0dd94..be68c95b3 100644
--- a/test/convert3.go
+++ b/test/convert3.go
@@ -13,8 +13,8 @@ var d1 chan<- int = c
var d2 = (chan<- int)(c)
var e *[4]int
-var f1 []int = e
-var f2 = []int(e)
+var f1 []int = e[0:]
+var f2 = []int(e[0:])
var g = []int(nil)
diff --git a/test/convlit.go b/test/convlit.go
index 22415bb32..94889d4a9 100644
--- a/test/convlit.go
+++ b/test/convlit.go
@@ -9,31 +9,31 @@ package main
// explicit conversion of constants is work in progress.
// the ERRORs in this block are debatable, but they're what
// the language spec says for now.
-var x1 = string(1);
-var x2 string = string(1);
-var x3 = int(1.5); // ERROR "convert|truncate"
-var x4 int = int(1.5); // ERROR "convert|truncate"
-var x5 = "a" + string(1);
-var x6 = int(1e100); // ERROR "overflow"
-var x7 = float(1e1000); // ERROR "overflow"
+var x1 = string(1)
+var x2 string = string(1)
+var x3 = int(1.5) // ERROR "convert|truncate"
+var x4 int = int(1.5) // ERROR "convert|truncate"
+var x5 = "a" + string(1)
+var x6 = int(1e100) // ERROR "overflow"
+var x7 = float(1e1000) // ERROR "overflow"
// implicit conversions merit scrutiny
-var s string;
-var bad1 string = 1; // ERROR "conver|incompatible|invalid|cannot"
-var bad2 = s + 1; // ERROR "conver|incompatible|invalid"
-var bad3 = s + 'a'; // ERROR "conver|incompatible|invalid"
-var bad4 = "a" + 1; // ERROR "literals|incompatible|convert|invalid"
-var bad5 = "a" + 'a'; // ERROR "literals|incompatible|convert|invalid"
+var s string
+var bad1 string = 1 // ERROR "conver|incompatible|invalid|cannot"
+var bad2 = s + 1 // ERROR "conver|incompatible|invalid"
+var bad3 = s + 'a' // ERROR "conver|incompatible|invalid"
+var bad4 = "a" + 1 // ERROR "literals|incompatible|convert|invalid"
+var bad5 = "a" + 'a' // ERROR "literals|incompatible|convert|invalid"
-var bad6 int = 1.5; // ERROR "convert|truncate"
-var bad7 int = 1e100; // ERROR "overflow"
-var bad8 float32 = 1e200; // ERROR "overflow"
+var bad6 int = 1.5 // ERROR "convert|truncate"
+var bad7 int = 1e100 // ERROR "overflow"
+var bad8 float32 = 1e200 // ERROR "overflow"
// but these implicit conversions are okay
-var good1 string = "a";
-var good2 int = 1.0;
-var good3 int = 1e9;
-var good4 float = 1e20;
+var good1 string = "a"
+var good2 int = 1.0
+var good3 int = 1e9
+var good4 float = 1e20
// explicit conversion of string is okay
var _ = []int("abc")
diff --git a/test/copy.go b/test/copy.go
index 037d3f41f..0b5bddbed 100644
--- a/test/copy.go
+++ b/test/copy.go
@@ -23,6 +23,15 @@ var input32 = make([]uint32, N)
var output32 = make([]uint32, N)
var input64 = make([]uint64, N)
var output64 = make([]uint64, N)
+var inputS string
+var outputS = make([]uint8, N)
+
+type my8 []uint8
+type my16 []uint16
+type my32 []uint32
+type my32b []uint32
+type my64 []uint64
+type myS string
func u8(i int) uint8 {
i = 'a' + i%26
@@ -64,6 +73,7 @@ func reset() {
for i := range input8 {
input8[i] = u8(in)
output8[i] = u8(out)
+ outputS[i] = u8(out)
input16[i] = u16(in)
output16[i] = u16(out)
input32[i] = u32(in)
@@ -73,6 +83,7 @@ func reset() {
in++
out++
}
+ inputS = string(input8)
}
func clamp(n int) int {
@@ -95,13 +106,15 @@ func ncopied(length, in, out int) int {
func doAllSlices(length, in, out int) {
reset()
- n := copy(output8[out:clamp(out+length)], input8[in:clamp(in+length)])
+ n := copy(my8(output8[out:clamp(out+length)]), input8[in:clamp(in+length)])
verify8(length, in, out, n)
- n = copy(output16[out:clamp(out+length)], input16[in:clamp(in+length)])
+ n = copy(my8(outputS[out:clamp(out+length)]), myS(inputS[in:clamp(in+length)]))
+ verifyS(length, in, out, n)
+ n = copy(my16(output16[out:clamp(out+length)]), input16[in:clamp(in+length)])
verify16(length, in, out, n)
- n = copy(output32[out:clamp(out+length)], input32[in:clamp(in+length)])
+ n = copy(my32(output32[out:clamp(out+length)]), my32b(input32[in:clamp(in+length)]))
verify32(length, in, out, n)
- n = copy(output64[out:clamp(out+length)], input64[in:clamp(in+length)])
+ n = copy(my64(output64[out:clamp(out+length)]), input64[in:clamp(in+length)])
verify64(length, in, out, n)
}
@@ -145,6 +158,46 @@ func verify8(length, in, out, m int) {
}
}
+func badS(state string, i, length, in, out int) {
+ fmt.Printf("%s bad(%d %d %d): %c not %c:\n\t%s\n\t%s\n",
+ state,
+ length, in, out,
+ outputS[i],
+ uint8(i+13),
+ inputS, outputS)
+ os.Exit(1)
+}
+
+func verifyS(length, in, out, m int) {
+ n := ncopied(length, in, out)
+ if m != n {
+ fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
+ return
+ }
+ // before
+ var i int
+ for i = 0; i < out; i++ {
+ if outputS[i] != u8(i+13) {
+ badS("beforeS", i, length, in, out)
+ return
+ }
+ }
+ // copied part
+ for ; i < out+n; i++ {
+ if outputS[i] != u8(i+in-out) {
+ badS("copiedS", i, length, in, out)
+ return
+ }
+ }
+ // after
+ for ; i < len(outputS); i++ {
+ if outputS[i] != u8(i+13) {
+ badS("afterS", i, length, in, out)
+ return
+ }
+ }
+}
+
func bad16(state string, i, length, in, out int) {
fmt.Printf("%s bad(%d %d %d): %x not %x:\n\t%v\n\t%v\n",
state,
diff --git a/test/ddd.go b/test/ddd.go
index c9949c36e..b95d6e883 100644
--- a/test/ddd.go
+++ b/test/ddd.go
@@ -14,13 +14,13 @@ func sum(args ...int) int {
return s
}
-func sumC(args ...int) int { return func() int { return sum(args) }() }
+func sumC(args ...int) int { return func() int { return sum(args...) }() }
-var sumD = func(args ...int) int { return sum(args) }
+var sumD = func(args ...int) int { return sum(args...) }
-var sumE = func() func(...int) int { return func(args ...int) int { return sum(args) } }()
+var sumE = func() func(...int) int { return func(args ...int) int { return sum(args...) } }()
-var sumF = func(args ...int) func() int { return func() int { return sum(args) } }
+var sumF = func(args ...int) func() int { return func() int { return sum(args...) } }
func sumA(args []int) int {
s := 0
@@ -30,10 +30,14 @@ func sumA(args []int) int {
return s
}
-func sum2(args ...int) int { return 2 * sum(args) }
+func sumB(args []int) int { return sum(args...) }
+
+func sum2(args ...int) int { return 2 * sum(args...) }
func sum3(args ...int) int { return 3 * sumA(args) }
+func sum4(args ...int) int { return 4 * sumB(args) }
+
func intersum(args ...interface{}) int {
s := 0
for _, v := range args {
@@ -46,9 +50,9 @@ type T []T
func ln(args ...T) int { return len(args) }
-func ln2(args ...T) int { return 2 * ln(args) }
+func ln2(args ...T) int { return 2 * ln(args...) }
-func (*T) Sum(args ...int) int { return sum(args) }
+func (*T) Sum(args ...int) int { return sum(args...) }
type U struct {
*T
@@ -119,6 +123,22 @@ func main() {
println("sum 9", x)
panic("fail")
}
+ if x := sum4(1, 2, 3); x != 4*6 {
+ println("sum 6", x)
+ panic("fail")
+ }
+ if x := sum4(); x != 4*0 {
+ println("sum 0", x)
+ panic("fail")
+ }
+ if x := sum4(10); x != 4*10 {
+ println("sum 10", x)
+ panic("fail")
+ }
+ if x := sum4(1, 8); x != 4*9 {
+ println("sum 9", x)
+ panic("fail")
+ }
if x := intersum(1, 2, 3); x != 6 {
println("intersum 6", x)
panic("fail")
diff --git a/test/ddd1.go b/test/ddd1.go
index 6f714c078..fcd32c282 100644
--- a/test/ddd1.go
+++ b/test/ddd1.go
@@ -6,6 +6,8 @@
package main
+import "unsafe"
+
func sum(args ...int) int { return 0 }
var (
@@ -26,3 +28,20 @@ var (
_ = funny(nil, nil)
_ = funny([]T{}) // ok because []T{} is a T; passes []T{[]T{}}
)
+
+func bad(args ...int) {
+ print(1, 2, args...) // ERROR "[.][.][.]"
+ println(args...) // ERROR "[.][.][.]"
+ ch := make(chan int)
+ close(ch...) // ERROR "[.][.][.]"
+ _ = len(args...) // ERROR "[.][.][.]"
+ _ = closed(ch...) // ERROR "[.][.][.]"
+ _ = new(int...) // ERROR "[.][.][.]"
+ n := 10
+ _ = make([]byte, n...) // ERROR "[.][.][.]"
+ // TODO(rsc): enable after gofmt bug is fixed
+ // _ = make([]byte, 10 ...) // error "[.][.][.]"
+ var x int
+ _ = unsafe.Pointer(&x...) // ERROR "[.][.][.]"
+ _ = unsafe.Sizeof(x...) // ERROR "[.][.][.]"
+}
diff --git a/test/decl.go b/test/decl.go
index 6e8cbab20..c31082bcf 100644
--- a/test/decl.go
+++ b/test/decl.go
@@ -13,28 +13,28 @@ func f2() (float, int) { return 1, 2 }
func f3() (float, int, string) { return 1, 2, "3" }
func x() (s string) {
- a, b, s := f3();
- _, _ = a, b;
+ a, b, s := f3()
+ _, _ = a, b
return // tests that result var is in scope for redeclaration
}
func main() {
- i, f, s := f3();
- j, f := f2(); // redeclare f
- k := f1();
- m, g, s := f3();
- m, h, s := f3();
+ i, f, s := f3()
+ j, f := f2() // redeclare f
+ k := f1()
+ m, g, s := f3()
+ m, h, s := f3()
{
// new block should be ok.
- i, f, s := f3();
- j, f := f2(); // redeclare f
- k := f1();
- m, g, s := f3();
- m, h, s := f3();
- _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h;
+ i, f, s := f3()
+ j, f := f2() // redeclare f
+ k := f1()
+ m, g, s := f3()
+ m, h, s := f3()
+ _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
}
if x() != "3" {
- println("x() failed");
+ println("x() failed")
}
- _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h;
+ _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
}
diff --git a/test/declbad.go b/test/declbad.go
index 5fbb04ab5..269ebdefb 100644
--- a/test/declbad.go
+++ b/test/declbad.go
@@ -15,44 +15,44 @@ func f3() (float, int, string) { return 1, 2, "3" }
func main() {
{
// simple redeclaration
- i := f1();
- i := f1(); // ERROR "redeclared|no new"
- _ = i;
+ i := f1()
+ i := f1() // ERROR "redeclared|no new"
+ _ = i
}
{
// change of type for f
- i, f, s := f3();
- f, g, t := f3(); // ERROR "redeclared|cannot assign|incompatible"
- _, _, _, _, _ = i, f, s, g, t;
+ i, f, s := f3()
+ f, g, t := f3() // ERROR "redeclared|cannot assign|incompatible"
+ _, _, _, _, _ = i, f, s, g, t
}
{
// change of type for i
- i, f, s := f3();
- j, i, t := f3(); // ERROR "redeclared|cannot assign|incompatible"
- _, _, _, _, _ = i, f, s, j, t;
+ i, f, s := f3()
+ j, i, t := f3() // ERROR "redeclared|cannot assign|incompatible"
+ _, _, _, _, _ = i, f, s, j, t
}
{
// no new variables
- i, f, s := f3();
- i, f := f2(); // ERROR "redeclared|no new"
- _, _, _ = i, f, s;
+ i, f, s := f3()
+ i, f := f2() // ERROR "redeclared|no new"
+ _, _, _ = i, f, s
}
{
// single redeclaration
- i, f, s := f3();
- i := f1(); // ERROR "redeclared|no new|incompatible"
- _, _, _ = i, f, s;
+ i, f, s := f3()
+ i := f1() // ERROR "redeclared|no new|incompatible"
+ _, _, _ = i, f, s
}
// double redeclaration
{
- i, f, s := f3();
- i, f := f2(); // ERROR "redeclared|no new"
- _, _, _ = i, f, s;
+ i, f, s := f3()
+ i, f := f2() // ERROR "redeclared|no new"
+ _, _, _ = i, f, s
}
{
// triple redeclaration
- i, f, s := f3();
- i, f, s := f3(); // ERROR "redeclared|no new"
- _, _, _ = i, f, s;
+ i, f, s := f3()
+ i, f, s := f3() // ERROR "redeclared|no new"
+ _, _, _ = i, f, s
}
}
diff --git a/test/defer.go b/test/defer.go
index 8b8312235..bef8fbe26 100644
--- a/test/defer.go
+++ b/test/defer.go
@@ -26,7 +26,7 @@ func test1() {
}
}
-func addDotDotDot(v ...interface{}) { result += fmt.Sprint(v) }
+func addDotDotDot(v ...interface{}) { result += fmt.Sprint(v...) }
func test2helper() {
for i := 0; i < 10; i++ {
diff --git a/test/env.go b/test/env.go
index b12a72973..16b207644 100644
--- a/test/env.go
+++ b/test/env.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # NaCl runner does not expose environment
// $G $F.go && $L $F.$A && ./$A.out
// Copyright 2009 The Go Authors. All rights reserved.
@@ -10,18 +9,18 @@ package main
import os "os"
func main() {
- ga, e0 := os.Getenverror("GOARCH");
+ ga, e0 := os.Getenverror("GOARCH")
if e0 != nil {
- print("$GOARCH: ", e0.String(), "\n");
- os.Exit(1);
+ print("$GOARCH: ", e0.String(), "\n")
+ os.Exit(1)
}
if ga != "amd64" && ga != "386" && ga != "arm" {
- print("$GOARCH=", ga, "\n");
- os.Exit(1);
+ print("$GOARCH=", ga, "\n")
+ os.Exit(1)
}
- xxx, e1 := os.Getenverror("DOES_NOT_EXIST");
+ xxx, e1 := os.Getenverror("DOES_NOT_EXIST")
if e1 != os.ENOENV {
- print("$DOES_NOT_EXIST=", xxx, "; err = ", e1.String(), "\n");
- os.Exit(1);
+ print("$DOES_NOT_EXIST=", xxx, "; err = ", e1.String(), "\n")
+ os.Exit(1)
}
}
diff --git a/test/eof.go b/test/eof.go
new file mode 100644
index 000000000..81f9fd028
--- /dev/null
+++ b/test/eof.go
@@ -0,0 +1,9 @@
+// $G $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.
+
+// No newline at the end of this file.
+
+package main \ No newline at end of file
diff --git a/test/syntax/slice.go b/test/eof1.go
index 7675ca187..c39a3cfdb 100644
--- a/test/syntax/slice.go
+++ b/test/eof1.go
@@ -1,4 +1,4 @@
-// errchk $G -e $D/$F.go
+// $G $D/$F.go
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
@@ -6,4 +6,4 @@
package main
-var x = y[:z] // ERROR "missing lower bound in slice expression|undefined"
+// No newline at the end of this comment. \ No newline at end of file
diff --git a/test/errchk b/test/errchk
index 115aa7be0..b0edd7a6b 100755
--- a/test/errchk
+++ b/test/errchk
@@ -3,30 +3,38 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-# This script checks that the compilers emits the errors which we
-# expect. Usage: errchk COMPILER [OPTS] SOURCEFILE. This will run
-# the command COMPILER [OPTS] SOURCEFILE. The compilation is expected
-# to fail; if it succeeds, this script will report an error. The
-# stderr output of the compiler will be matched against comments in
-# SOURCEFILE. For each line of the source file which should generate
-# an error, there should be a comment of the form // ERROR "regexp".
-# If the compiler generates an error for a line which has no such
-# commnt, this script will report an error. Likewise if the compiler
-# does not generate an error for a line which has a comment, or if the
-# error message does not match the <regexp>. The <regexp> syntax
-# is Perl but its best to stick to egrep.
+# This script checks that the compilers emit the errors which we expect.
+# Usage: errchk COMPILER [OPTS] SOURCEFILES. This will run the command
+# COMPILER [OPTS] SOURCEFILES. The compilation is expected to fail; if
+# it succeeds, this script will report an error. The stderr output of
+# the compiler will be matched against comments in SOURCEFILES. For each
+# line of the source files which should generate an error, there should
+# be a comment of the form // ERROR "regexp". If the compiler generates
+# an error for a line which has no such comment, this script will report
+# an error. Likewise if the compiler does not generate an error for a
+# line which has a comment, or if the error message does not match the
+# <regexp>. The <regexp> syntax is Perl but its best to stick to egrep.
use POSIX;
if(@ARGV < 1) {
- print STDERR "Usage: errchk COMPILER [OPTS] SOURCEFILE\n";
+ print STDERR "Usage: errchk COMPILER [OPTS] SOURCEFILES\n";
exit 1;
}
-$file = $ARGV[@ARGV-1];
-open(SRC, $file) || die "BUG: errchk: open $file: $!";
-@src = <SRC>;
-close(SRC);
+# Grab SOURCEFILES
+foreach(reverse 0 .. @ARGV-1) {
+ unless($ARGV[$_] =~ /\.go$/) {
+ @file = @ARGV[$_+1 .. @ARGV-1];
+ last;
+ }
+}
+
+foreach $file (@file) {
+ open(SRC, $file) || die "BUG: errchk: open $file: $!";
+ $src{$file} = [<SRC>];
+ close(SRC);
+}
# Run command
$cmd = join(' ', @ARGV);
@@ -57,35 +65,45 @@ sub bug() {
}
}
-$line = 0;
-foreach $src (@src) {
- $line++;
- next unless $src =~ m|// ERROR (.*)|;
- $regexp = $1;
- if($regexp !~ /^"([^"]*)"/) {
- print STDERR "$file:$line: malformed regexp\n";
- next;
- }
- $regexp = $1;
-
- @errmsg = grep { /$file:$line:/ } @out;
- @out = grep { !/$file:$line:/ } @out;
- if(@errmsg == 0) {
- bug();
- print STDERR "errchk: $file:$line: missing expected error: '$regexp'\n";
- next;
- }
- @match = grep { /$regexp/ } @errmsg;
- if(@match == 0) {
- bug();
- print STDERR "errchk: $file:$line: error message does not match '$regexp'\n";
- next;
+sub chk {
+ my $file = shift;
+ my $line = 0;
+ my $regexp;
+ my @errmsg;
+ my @match;
+ foreach my $src (@{$src{$file}}) {
+ $line++;
+ next unless $src =~ m|// (GC_)?ERROR (.*)|;
+ $regexp = $2;
+ if($regexp !~ /^"([^"]*)"/) {
+ print STDERR "$file:$line: malformed regexp\n";
+ next;
+ }
+ $regexp = $1;
+
+ @errmsg = grep { /$file:$line[:[]/ } @out;
+ @out = grep { !/$file:$line[:[]/ } @out;
+ if(@errmsg == 0) {
+ bug();
+ print STDERR "errchk: $file:$line: missing expected error: '$regexp'\n";
+ next;
+ }
+ @match = grep { /$regexp/ } @errmsg;
+ if(@match == 0) {
+ bug();
+ print STDERR "errchk: $file:$line: error message does not match '$regexp'\n";
+ next;
+ }
}
}
+foreach $file (@file) {
+ chk($file)
+}
+
if(@out != 0) {
bug();
- print STDERR "errchk: $file: unmatched error messages:\n";
+ print STDERR "errchk: unmatched error messages:\n";
print STDERR "==================================================\n";
print STDERR @out;
print STDERR "==================================================\n";
diff --git a/test/escape.go b/test/escape.go
index 19c08a527..d4d844704 100644
--- a/test/escape.go
+++ b/test/escape.go
@@ -14,142 +14,142 @@ package main
var bad = false
-var allptr = make([]*int, 0, 100);
+var allptr = make([]*int, 0, 100)
func noalias(p, q *int, s string) {
- n := len(allptr);
- *p = -(n+1);
- *q = -(n+2);
- allptr = allptr[0:n+2];
- allptr[n] = p;
- allptr[n+1] = q;
- n += 2;
+ n := len(allptr)
+ *p = -(n+1)
+ *q = -(n+2)
+ allptr = allptr[0:n+2]
+ allptr[n] = p
+ allptr[n+1] = q
+ n += 2
for i := 0; i < n; i++ {
if allptr[i] != nil && *allptr[i] != -(i+1) {
- println("aliased pointers", -(i+1), *allptr[i], "after", s);
- allptr[i] = nil;
- bad = true;
+ println("aliased pointers", -(i+1), *allptr[i], "after", s)
+ allptr[i] = nil
+ bad = true
}
}
}
func val(p, q *int, v int, s string) {
if *p != v {
- println("wrong value want", v, "got", *p, "after", s);
- bad = true;
+ println("wrong value want", v, "got", *p, "after", s)
+ bad = true
}
if *q != v+1 {
- println("wrong value want", v+1, "got", *q, "after", s);
- bad = true;
+ println("wrong value want", v+1, "got", *q, "after", s)
+ bad = true
}
}
func chk(p, q *int, v int, s string) {
- val(p, q, v, s);
- noalias(p, q, s);
+ val(p, q, v, s)
+ noalias(p, q, s)
}
func chkalias(p, q *int, v int, s string) {
if p != q {
- println("want aliased pointers but got different after", s);
+ println("want aliased pointers but got different after", s)
}
if *q != v+1 {
- println("wrong value want", v+1, "got", *q, "after", s);
+ println("wrong value want", v+1, "got", *q, "after", s)
}
}
func i_escapes(x int) *int {
- var i int;
- i = x;
- return &i;
+ var i int
+ i = x
+ return &i
}
func j_escapes(x int) *int {
- var j int = x;
- j = x;
- return &j;
+ var j int = x
+ j = x
+ return &j
}
func k_escapes(x int) *int {
- k := x;
- return &k;
+ k := x
+ return &k
}
func in_escapes(x int) *int {
- return &x;
+ return &x
}
func send(c chan int, x int) {
- c <- x;
+ c <- x
}
func select_escapes(x int) *int {
- c := make(chan int);
- go send(c, x);
+ c := make(chan int)
+ go send(c, x)
select {
case req := <-c:
- return &req;
+ return &req
}
- return nil;
+ return nil
}
func select_escapes1(x int, y int) (*int, *int) {
- c := make(chan int);
- var a [2]int;
- var p [2]*int;
- a[0] = x;
- a[1] = y;
+ c := make(chan int)
+ var a [2]int
+ var p [2]*int
+ a[0] = x
+ a[1] = y
for i := 0; i < 2; i++ {
- go send(c, a[i]);
+ go send(c, a[i])
select {
case req := <-c:
- p[i] = &req;
+ p[i] = &req
}
}
return p[0], p[1]
}
func range_escapes(x int) *int {
- var a [1]int;
- a[0] = x;
+ var a [1]int
+ a[0] = x
for _, v := range a {
- return &v;
+ return &v
}
- return nil;
+ return nil
}
// *is* aliased
func range_escapes2(x, y int) (*int, *int) {
- var a [2]int;
- var p [2]*int;
- a[0] = x;
- a[1] = y;
+ var a [2]int
+ var p [2]*int
+ a[0] = x
+ a[1] = y
for k, v := range a {
- p[k] = &v;
+ p[k] = &v
}
return p[0], p[1]
}
// *is* aliased
func for_escapes2(x int, y int) (*int, *int) {
- var p [2]*int;
- n := 0;
+ var p [2]*int
+ n := 0
for i := x; n < 2; i = y {
- p[n] = &i;
- n++;
+ p[n] = &i
+ n++
}
return p[0], p[1]
}
func out_escapes(i int) (x int, p *int) {
x = i
- p = &x; // ERROR "address of out parameter"
- return;
+ p = &x // ERROR "address of out parameter"
+ return
}
func out_escapes_2(i int) (x int, p *int) {
x = i
- return x, &x; // ERROR "address of out parameter"
+ return x, &x // ERROR "address of out parameter"
}
func defer1(i int) (x int) {
@@ -160,40 +160,40 @@ func defer1(i int) (x int) {
}
func main() {
- p, q := i_escapes(1), i_escapes(2);
- chk(p, q, 1, "i_escapes");
+ p, q := i_escapes(1), i_escapes(2)
+ chk(p, q, 1, "i_escapes")
- p, q = j_escapes(3), j_escapes(4);
- chk(p, q, 3, "j_escapes");
+ p, q = j_escapes(3), j_escapes(4)
+ chk(p, q, 3, "j_escapes")
- p, q = k_escapes(5), k_escapes(6);
- chk(p, q, 5, "k_escapes");
+ p, q = k_escapes(5), k_escapes(6)
+ chk(p, q, 5, "k_escapes")
- p, q = in_escapes(7), in_escapes(8);
- chk(p, q, 7, "in_escapes");
+ p, q = in_escapes(7), in_escapes(8)
+ chk(p, q, 7, "in_escapes")
- p, q = select_escapes(9), select_escapes(10);
- chk(p, q, 9, "select_escapes");
+ p, q = select_escapes(9), select_escapes(10)
+ chk(p, q, 9, "select_escapes")
- p, q = select_escapes1(11, 12);
- chk(p, q, 11, "select_escapes1");
+ p, q = select_escapes1(11, 12)
+ chk(p, q, 11, "select_escapes1")
- p, q = range_escapes(13), range_escapes(14);
- chk(p, q, 13, "range_escapes");
+ p, q = range_escapes(13), range_escapes(14)
+ chk(p, q, 13, "range_escapes")
- p, q = range_escapes2(101, 102);
- chkalias(p, q, 101, "range_escapes2");
+ p, q = range_escapes2(101, 102)
+ chkalias(p, q, 101, "range_escapes2")
- p, q = for_escapes2(103, 104);
- chkalias(p, q, 103, "for_escapes2");
+ p, q = for_escapes2(103, 104)
+ chkalias(p, q, 103, "for_escapes2")
_, p = out_escapes(15)
- _, q = out_escapes(16);
- chk(p, q, 15, "out_escapes");
+ _, q = out_escapes(16)
+ chk(p, q, 15, "out_escapes")
_, p = out_escapes_2(17)
- _, q = out_escapes_2(18);
- chk(p, q, 17, "out_escapes_2");
+ _, q = out_escapes_2(18)
+ chk(p, q, 17, "out_escapes_2")
x := defer1(20)
if x != 20 {
@@ -202,6 +202,6 @@ func main() {
}
if bad {
- panic("BUG: no escape");
+ panic("BUG: no escape")
}
}
diff --git a/test/fixedbugs/bug045.go b/test/fixedbugs/bug045.go
index d8a712c6d..94888c40e 100644
--- a/test/fixedbugs/bug045.go
+++ b/test/fixedbugs/bug045.go
@@ -13,7 +13,7 @@ type T struct {
func main() {
var ta []*T;
- ta = new([1]*T);
+ ta = new([1]*T)[0:];
ta[0] = nil;
}
/*
diff --git a/test/fixedbugs/bug059.go b/test/fixedbugs/bug059.go
index b190d4f26..6a77367d6 100644
--- a/test/fixedbugs/bug059.go
+++ b/test/fixedbugs/bug059.go
@@ -25,7 +25,7 @@ func main() {
as := new([2]string);
as[0] = "0";
as[1] = "1";
- m["0"] = as;
+ m["0"] = as[0:];
a := m["0"];
a[0] = "x";
diff --git a/test/fixedbugs/bug146.go b/test/fixedbugs/bug146.go
index bfb7529d6..16324c741 100644
--- a/test/fixedbugs/bug146.go
+++ b/test/fixedbugs/bug146.go
@@ -9,7 +9,7 @@ package main
func main() {
type Slice []byte;
a := [...]byte{ 0 };
- b := Slice(&a); // This should be OK.
+ b := Slice(a[0:]); // This should be OK.
c := Slice(a); // ERROR "invalid|illegal|cannot"
_, _ = b, c;
}
diff --git a/test/fixedbugs/bug195.go b/test/fixedbugs/bug195.go
index 27bbbd354..65ab02a03 100644
--- a/test/fixedbugs/bug195.go
+++ b/test/fixedbugs/bug195.go
@@ -19,9 +19,9 @@ type I4 interface {
}
type I5 interface {
- I6
+ I6 // GCCGO_ERROR "interface"
}
type I6 interface {
- I5 // ERROR "interface"
+ I5 // GC_ERROR "interface"
}
diff --git a/test/fixedbugs/bug206.go b/test/fixedbugs/bug206.go
index 3879e8cbd..7efc0b14a 100644
--- a/test/fixedbugs/bug206.go
+++ b/test/fixedbugs/bug206.go
@@ -10,14 +10,14 @@ import "go/ast";
func g(list []ast.Expr) {
n := len(list)-1;
- println(list[n].Pos().Line);
+ println(list[n].Pos());
}
// f is the same as g except that the expression assigned to n is inlined.
func f(list []ast.Expr) {
// n := len(list)-1;
- println(list[len(list)-1 /* n */].Pos().Line);
+ println(list[len(list)-1 /* n */].Pos());
}
diff --git a/test/fixedbugs/bug243.go b/test/fixedbugs/bug243.go
index 30dbc4ed4..236c14402 100644
--- a/test/fixedbugs/bug243.go
+++ b/test/fixedbugs/bug243.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # no network
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2010 The Go Authors. All rights reserved.
@@ -8,22 +7,19 @@
package main
import (
- "fmt"
"net"
- "os"
)
func main() {
- os.Stdout.Close()
var listen, _ = net.Listen("tcp", "127.0.0.1:0")
go func() {
for {
var conn, _ = listen.Accept()
- fmt.Println("[SERVER] ", conn)
+ _ = conn
}
}()
var conn, _ = net.Dial("tcp", "", listen.Addr().String())
- fmt.Println("[CLIENT] ", conn)
+ _ = conn
}
diff --git a/test/fixedbugs/bug251.go b/test/fixedbugs/bug251.go
index 37dec9055..c94ad2abe 100644
--- a/test/fixedbugs/bug251.go
+++ b/test/fixedbugs/bug251.go
@@ -8,14 +8,14 @@ package main
type I1 interface {
m() I2
- I2
+ I2 // GCCGO_ERROR "loop|interface"
}
type I2 interface {
- I1 // ERROR "loop|interface"
+ I1 // GC_ERROR "loop|interface"
}
-var i1 I1 = i2 // ERROR "missing m method|need type assertion"
+var i1 I1 = i2 // GC_ERROR "missing m method|need type assertion"
var i2 I2
var i2a I2 = i1
diff --git a/test/fixedbugs/bug252.go b/test/fixedbugs/bug252.go
index bd11b86eb..5615f84fa 100644
--- a/test/fixedbugs/bug252.go
+++ b/test/fixedbugs/bug252.go
@@ -7,9 +7,9 @@
package main
func f(args ...int) {
- g(args) // ERROR "[.][.][.] mismatch"
+ g(args) // ERROR "[.][.][.]"
}
func g(args ...interface{}) {
- f(args) // ERROR "[.][.][.] mismatch"
+ f(args) // ERROR "[.][.][.]"
}
diff --git a/test/fixedbugs/bug255.go b/test/fixedbugs/bug255.go
index 4003a780c..44427cfdb 100644
--- a/test/fixedbugs/bug255.go
+++ b/test/fixedbugs/bug255.go
@@ -9,7 +9,7 @@ package main
var a [10]int // ok
var b [1e1]int // ok
var c [1.5]int // ERROR "truncated"
-var d ["abc"]int // ERROR "invalid array bound"
-var e [nil]int // ERROR "invalid array bound"
-var f [e]int // ERROR "invalid array bound"
+var d ["abc"]int // ERROR "invalid array bound|not numeric"
+var e [nil]int // ERROR "invalid array bound|not numeric"
+var f [e]int // ERROR "invalid array bound|not constant"
var g [1<<65]int // ERROR "overflows"
diff --git a/test/bugs/bug260.go b/test/fixedbugs/bug260.go
index 6a6331e65..34757c70e 100644
--- a/test/bugs/bug260.go
+++ b/test/fixedbugs/bug260.go
@@ -10,9 +10,15 @@ import (
"strconv"
)
-type T1 struct { x uint8 }
-type T2 struct { x uint16 }
-type T4 struct { x uint32 }
+type T1 struct {
+ x uint8
+}
+type T2 struct {
+ x uint16
+}
+type T4 struct {
+ x uint32
+}
func main() {
report := len(os.Args) > 1
@@ -20,7 +26,7 @@ func main() {
var b1 [10]T1
a0, _ := strconv.Btoui64(fmt.Sprintf("%p", &b1[0])[2:], 16)
a1, _ := strconv.Btoui64(fmt.Sprintf("%p", &b1[1])[2:], 16)
- if a1 != a0 + 1 {
+ if a1 != a0+1 {
fmt.Println("FAIL")
if report {
fmt.Println("alignment should be 1, is", a1-a0)
@@ -30,7 +36,7 @@ func main() {
var b2 [10]T2
a0, _ = strconv.Btoui64(fmt.Sprintf("%p", &b2[0])[2:], 16)
a1, _ = strconv.Btoui64(fmt.Sprintf("%p", &b2[1])[2:], 16)
- if a1 != a0 + 2 {
+ if a1 != a0+2 {
if status == 0 {
fmt.Println("FAIL")
status = 1
@@ -42,7 +48,7 @@ func main() {
var b4 [10]T4
a0, _ = strconv.Btoui64(fmt.Sprintf("%p", &b4[0])[2:], 16)
a1, _ = strconv.Btoui64(fmt.Sprintf("%p", &b4[1])[2:], 16)
- if a1 != a0 + 4 {
+ if a1 != a0+4 {
if status == 0 {
fmt.Println("FAIL")
status = 1
diff --git a/test/fixedbugs/bug273.go b/test/fixedbugs/bug273.go
index ff8f1c6af..816f69e8f 100644
--- a/test/fixedbugs/bug273.go
+++ b/test/fixedbugs/bug273.go
@@ -15,6 +15,8 @@ var bug = false
var minus1 = -1
var big int64 = 10 | 1<<32
+var g1 []int
+
func shouldfail(f func(), desc string) {
defer func() { recover() }()
f()
@@ -26,52 +28,56 @@ func shouldfail(f func(), desc string) {
}
func badlen() {
- _ = make([]int, minus1)
+ g1 = make([]int, minus1)
}
func biglen() {
- _ = make([]int, big)
+ g1 = make([]int, big)
}
func badcap() {
- _ = make([]int, 10, minus1)
+ g1 = make([]int, 10, minus1)
}
func badcap1() {
- _ = make([]int, 10, 5)
+ g1 = make([]int, 10, 5)
}
func bigcap() {
- _ = make([]int, 10, big)
+ g1 = make([]int, 10, big)
}
const (
addrBits = 8*uint(unsafe.Sizeof((*byte)(nil)))
sh = addrBits/2 - 2
)
+var g2 [][1<<sh][1<<sh]byte
func overflow() {
- _ = make([][1<<sh][1<<sh]byte, 64)
+ g2 = make([][1<<sh][1<<sh]byte, 64)
}
+var g3 map[int]int
func badmapcap() {
- _ = make(map[int]int, minus1)
+ g3 = make(map[int]int, minus1)
}
func bigmapcap() {
- _ = make(map[int]int, big)
+ g3 = make(map[int]int, big)
}
+var g4 chan int
func badchancap() {
- _ = make(chan int, minus1)
+ g4 = make(chan int, minus1)
}
func bigchancap() {
- _ = make(chan int, big)
+ g4 = make(chan int, big)
}
+var g5 chan [1<<15]byte
func overflowchan() {
if addrBits == 32 {
- _ = make(chan [1<<15]byte, 1<<20)
+ g5 = make(chan [1<<15]byte, 1<<20)
} else {
// cannot overflow on 64-bit, because
// int is 32 bits and max chan value size
diff --git a/test/bugs/bug274.go b/test/fixedbugs/bug274.go
index 621f31eed..621f31eed 100644
--- a/test/bugs/bug274.go
+++ b/test/fixedbugs/bug274.go
diff --git a/test/fixedbugs/bug278.go b/test/fixedbugs/bug278.go
index 8c804cfe4..3699b9a14 100644
--- a/test/fixedbugs/bug278.go
+++ b/test/fixedbugs/bug278.go
@@ -15,9 +15,9 @@ func f() [10]int {
var m map[int][10]int
func main() {
- f()[1] = 2 // ERROR "cannot"
- f()[2:3][0] = 4 // ERROR "cannot"
+ f()[1] = 2 // ERROR "cannot|invalid"
+ f()[2:3][0] = 4 // ERROR "cannot|addressable"
var x = "abc"
- x[2] = 3 // ERROR "cannot"
- m[0][5] = 6 // ERROR "cannot"
+ x[2] = 3 // ERROR "cannot|invalid"
+ m[0][5] = 6 // ERROR "cannot|invalid"
}
diff --git a/test/fixedbugs/bug284.go b/test/fixedbugs/bug284.go
index 9e9949bed..bcf161e3d 100644
--- a/test/fixedbugs/bug284.go
+++ b/test/fixedbugs/bug284.go
@@ -30,12 +30,12 @@ func main() {
var a2 A2
a0 = a0
a0 = a1
- a0 = [3]int(a2) // ERROR "cannot"
+ a0 = [3]int(a2) // ERROR "cannot|invalid"
a1 = a0
a1 = a1
- a1 = A1(a2) // ERROR "cannot"
- a2 = A2(a0) // ERROR "cannot"
- a2 = A2(a1) // ERROR "cannot"
+ a1 = A1(a2) // ERROR "cannot|invalid"
+ a2 = A2(a0) // ERROR "cannot|invalid"
+ a2 = A2(a1) // ERROR "cannot|invalid"
a2 = a2
type S1 struct {
@@ -53,12 +53,12 @@ func main() {
s0 = s1
s0 = struct {
x int
- }(s2) // ERROR "cannot"
+ }(s2) // ERROR "cannot|invalid"
s1 = s0
s1 = s1
- s1 = S1(s2) // ERROR "cannot"
- s2 = S2(s0) // ERROR "cannot"
- s2 = S2(s1) // ERROR "cannot"
+ s1 = S1(s2) // ERROR "cannot|invalid"
+ s2 = S2(s0) // ERROR "cannot|invalid"
+ s2 = S2(s1) // ERROR "cannot|invalid"
s2 = s2
type P1 *int
@@ -68,12 +68,12 @@ func main() {
var p2 P2
p0 = p0
p0 = p1
- p0 = (*int)(p2) // ERROR "cannot"
+ p0 = (*int)(p2) // ERROR "cannot|invalid"
p1 = p0
p1 = p1
- p1 = P1(p2) // ERROR "cannot"
- p2 = P2(p0) // ERROR "cannot"
- p2 = P2(p1) // ERROR "cannot"
+ p1 = P1(p2) // ERROR "cannot|invalid"
+ p2 = P2(p0) // ERROR "cannot|invalid"
+ p2 = P2(p1) // ERROR "cannot|invalid"
p2 = p2
type Q1 *struct {
@@ -93,12 +93,12 @@ func main() {
})(ps1) // legal because of special conversion exception for pointers
q0 = (*struct {
x int
- })(q2) // ERROR "cannot"
+ })(q2) // ERROR "cannot|invalid"
q1 = q0
q1 = q1
- q1 = Q1(q2) // ERROR "cannot"
+ q1 = Q1(q2) // ERROR "cannot|invalid"
q2 = (*S1)(q0) // legal because of special conversion exception for pointers
- q2 = Q2(q1) // ERROR "cannot"
+ q2 = Q2(q1) // ERROR "cannot|invalid"
q2 = q2
type F1 func(x NewInt) int
@@ -108,12 +108,12 @@ func main() {
var f2 F2
f0 = f0
f0 = f1
- f0 = func(x NewInt) int(f2) // ERROR "cannot"
+ f0 = func(x NewInt) int(f2) // ERROR "cannot|invalid"
f1 = f0
f1 = f1
- f1 = F1(f2) // ERROR "cannot"
- f2 = F2(f0) // ERROR "cannot"
- f2 = F2(f1) // ERROR "cannot"
+ f1 = F1(f2) // ERROR "cannot|invalid"
+ f2 = F2(f0) // ERROR "cannot|invalid"
+ f2 = F2(f1) // ERROR "cannot|invalid"
f2 = f2
type X1 interface {
@@ -131,12 +131,12 @@ func main() {
x0 = x1
x0 = interface {
f() int
- }(x2) // ERROR "cannot|need type assertion"
+ }(x2) // ERROR "cannot|need type assertion|incompatible"
x1 = x0
x1 = x1
- x1 = X1(x2) // ERROR "cannot|need type assertion"
- x2 = X2(x0) // ERROR "cannot|need type assertion"
- x2 = X2(x1) // ERROR "cannot|need type assertion"
+ x1 = X1(x2) // ERROR "cannot|need type assertion|incompatible"
+ x2 = X2(x0) // ERROR "cannot|need type assertion|incompatible"
+ x2 = X2(x1) // ERROR "cannot|need type assertion|incompatible"
x2 = x2
type L1 []int
@@ -146,12 +146,12 @@ func main() {
var l2 L2
l0 = l0
l0 = l1
- l0 = []int(l2) // ERROR "cannot"
+ l0 = []int(l2) // ERROR "cannot|invalid"
l1 = l0
l1 = l1
- l1 = L1(l2) // ERROR "cannot"
- l2 = L2(l0) // ERROR "cannot"
- l2 = L2(l1) // ERROR "cannot"
+ l1 = L1(l2) // ERROR "cannot|invalid"
+ l2 = L2(l0) // ERROR "cannot|invalid"
+ l2 = L2(l1) // ERROR "cannot|invalid"
l2 = l2
type M1 map[string]int
@@ -161,12 +161,12 @@ func main() {
var m2 L2
m0 = m0
m0 = m1
- m0 = []int(m2) // ERROR "cannot"
+ m0 = []int(m2) // ERROR "cannot|invalid"
m1 = m0
m1 = m1
- m1 = L1(m2) // ERROR "cannot"
- m2 = L2(m0) // ERROR "cannot"
- m2 = L2(m1) // ERROR "cannot"
+ m1 = L1(m2) // ERROR "cannot|invalid"
+ m2 = L2(m0) // ERROR "cannot|invalid"
+ m2 = L2(m1) // ERROR "cannot|invalid"
m2 = m2
type C1 chan int
@@ -176,12 +176,12 @@ func main() {
var c2 C2
c0 = c0
c0 = c1
- c0 = chan int(c2) // ERROR "cannot"
+ c0 = chan int(c2) // ERROR "cannot|invalid"
c1 = c0
c1 = c1
- c1 = C1(c2) // ERROR "cannot"
- c2 = C2(c0) // ERROR "cannot"
- c2 = C2(c1) // ERROR "cannot"
+ c1 = C1(c2) // ERROR "cannot|invalid"
+ c2 = C2(c0) // ERROR "cannot|invalid"
+ c2 = C2(c1) // ERROR "cannot|invalid"
c2 = c2
// internal compiler error (6g and gccgo)
diff --git a/test/bugs/bug286.go b/test/fixedbugs/bug286.go
index 94423be81..94423be81 100644
--- a/test/bugs/bug286.go
+++ b/test/fixedbugs/bug286.go
diff --git a/test/fixedbugs/bug289.go b/test/fixedbugs/bug289.go
new file mode 100644
index 000000000..f7180ff04
--- /dev/null
+++ b/test/fixedbugs/bug289.go
@@ -0,0 +1,26 @@
+// errchk $G $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.
+
+// https://code.google.com/p/gofrontend/issues/detail?id=1
+
+package main
+
+func f1() {
+ a, b := f() // ERROR "mismatch|does not match"
+ _ = a
+ _ = b
+}
+
+func f2() {
+ var a, b int
+ a, b = f() // ERROR "mismatch|does not match"
+ _ = a
+ _ = b
+}
+
+func f() int {
+ return 1;
+}
diff --git a/test/fixedbugs/bug290.go b/test/fixedbugs/bug290.go
new file mode 100644
index 000000000..80437c7f8
--- /dev/null
+++ b/test/fixedbugs/bug290.go
@@ -0,0 +1,15 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+// http://code.google.com/p/go/issues/detail?id=920
+
+package main
+
+type X struct { x []X }
+
+func main() {
+ type Y struct { x []Y } // used to get invalid recursive type
+}
diff --git a/test/fixedbugs/bug291.go b/test/fixedbugs/bug291.go
new file mode 100644
index 000000000..09334c921
--- /dev/null
+++ b/test/fixedbugs/bug291.go
@@ -0,0 +1,23 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+// http://code.google.com/p/go/issues/detail?id=915
+
+package main
+
+type T struct {
+ x int
+}
+
+var t = &T{42}
+var i interface{} = t
+var tt, ok = i.(*T)
+
+func main() {
+ if tt == nil || tt.x != 42 {
+ println("BUG")
+ }
+}
diff --git a/test/fixedbugs/bug292.go b/test/fixedbugs/bug292.go
new file mode 100644
index 000000000..05852cd46
--- /dev/null
+++ b/test/fixedbugs/bug292.go
@@ -0,0 +1,22 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+// http://code.google.com/p/go/issues/detail?id=843
+
+package main
+
+import "unsafe"
+
+type T struct {
+ X, Y uint8
+}
+
+func main() {
+ var t T
+ if unsafe.Offsetof(t.X) != 0 || unsafe.Offsetof(t.Y) != 1 {
+ println("BUG", unsafe.Offsetof(t.X), unsafe.Offsetof(t.Y))
+ }
+}
diff --git a/test/fixedbugs/bug293.go b/test/fixedbugs/bug293.go
new file mode 100644
index 000000000..ca9b71a3a
--- /dev/null
+++ b/test/fixedbugs/bug293.go
@@ -0,0 +1,37 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+// http://code.google.com/p/go/issues/detail?id=846
+
+package main
+
+func x() (a int, b bool) {
+ defer func(){
+ a++
+ }()
+ a, b = y()
+ return
+}
+
+func x2() (a int, b bool) {
+ defer func(){
+ a++
+ }()
+ return y()
+}
+
+func y() (int, bool) {
+ return 4, false
+}
+
+func main() {
+ if a, _ := x(); a != 5 {
+ println("BUG", a)
+ }
+ if a, _ := x2(); a != 5 {
+ println("BUG", a)
+ }
+}
diff --git a/test/fixedbugs/bug294.go b/test/fixedbugs/bug294.go
new file mode 100644
index 000000000..18f45931c
--- /dev/null
+++ b/test/fixedbugs/bug294.go
@@ -0,0 +1,79 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+// http://code.google.com/p/go/issues/detail?id=800
+
+package main
+
+var log string
+
+type T int
+
+func (t T) a(s string) T {
+ log += "a(" + s + ")"
+ return t
+}
+
+func (T) b(s string) string {
+ log += "b"
+ return s
+}
+
+type F func(s string) F
+
+func a(s string) F {
+ log += "a(" + s + ")"
+ return F(a)
+}
+
+func b(s string) string {
+ log += "b"
+ return s
+}
+
+type I interface {
+ a(s string) I
+ b(s string) string
+}
+
+type T1 int
+
+func (t T1) a(s string) I {
+ log += "a(" + s + ")"
+ return t
+}
+
+func (T1) b(s string) string {
+ log += "b"
+ return s
+}
+
+var ok = true
+
+func bad() {
+ if !ok {
+ println("BUG")
+ ok = false
+ }
+ println(log)
+}
+
+func main() {
+ var t T
+ if t.a("1").a(t.b("2")); log != "a(1)ba(2)" {
+ bad()
+ }
+ log = ""
+ if a("3")(b("4"))(b("5")); log != "a(3)ba(4)ba(5)" {
+ bad()
+ }
+ log = ""
+ var i I = T1(0)
+ if i.a("6").a(i.b("7")).a(i.b("8")).a(i.b("9")); log != "a(6)ba(7)ba(8)ba(9)" {
+ bad()
+ }
+}
+
diff --git a/test/fixedbugs/bug295.go b/test/fixedbugs/bug295.go
new file mode 100644
index 000000000..fec2351f3
--- /dev/null
+++ b/test/fixedbugs/bug295.go
@@ -0,0 +1,17 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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 . "testing" // defines top-level T
+
+type S struct {
+ T int
+}
+
+func main() {
+ _ = &S{T: 1} // should work
+}
diff --git a/test/fixedbugs/bug296.go b/test/fixedbugs/bug296.go
new file mode 100644
index 000000000..46d8dbcfe
--- /dev/null
+++ b/test/fixedbugs/bug296.go
@@ -0,0 +1,88 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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 I interface {
+ m(a, b, c, d, e, f, g, h byte)
+}
+
+type Int8 int8
+
+func (x Int8) m(a, b, c, d, e, f, g, h byte) {
+ check("Int8", int64(x), 0x01, a, b, c, d, e, f, g, h)
+}
+
+type Uint8 uint8
+
+func (x Uint8) m(a, b, c, d, e, f, g, h byte) {
+ check("Uint8", int64(x), 0x01, a, b, c, d, e, f, g, h)
+}
+
+type Int16 int16
+
+func (x Int16) m(a, b, c, d, e, f, g, h byte) {
+ check("Int16", int64(x), 0x0102, a, b, c, d, e, f, g, h)
+}
+
+type Uint16 uint16
+
+func (x Uint16) m(a, b, c, d, e, f, g, h byte) {
+ check("Uint16", int64(x), 0x0102, a, b, c, d, e, f, g, h)
+}
+
+type Int32 int32
+
+func (x Int32) m(a, b, c, d, e, f, g, h byte) {
+ check("Int32", int64(x), 0x01020304, a, b, c, d, e, f, g, h)
+}
+
+type Uint32 uint32
+
+func (x Uint32) m(a, b, c, d, e, f, g, h byte) {
+ check("Uint32", int64(x), 0x01020304, a, b, c, d, e, f, g, h)
+}
+
+type Int64 int64
+
+func (x Int64) m(a, b, c, d, e, f, g, h byte) {
+ check("Int64", int64(x), 0x0102030405060708, a, b, c, d, e, f, g, h)
+}
+
+type Uint64 uint64
+
+func (x Uint64) m(a, b, c, d, e, f, g, h byte) {
+ check("Uint64", int64(x), 0x0102030405060708, a, b, c, d, e, f, g, h)
+}
+
+var test = []I{
+ Int8(0x01),
+ Uint8(0x01),
+ Int16(0x0102),
+ Uint16(0x0102),
+ Int32(0x01020304),
+ Uint32(0x01020304),
+ Int64(0x0102030405060708),
+ Uint64(0x0102030405060708),
+}
+
+func main() {
+ for _, t := range test {
+ t.m(0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)
+ }
+}
+
+var bug = false
+
+func check(desc string, have, want int64, a, b, c, d, e, f, g, h byte) {
+ if have != want || a != 0x10 || b != 0x11 || c != 0x12 || d != 0x13 || e != 0x14 || f != 0x15 || g != 0x16 || h != 0x17 {
+ if !bug {
+ bug = true
+ println("BUG")
+ }
+ println(desc, "check", have, want, a, b, c, d, e, f, g, h)
+ }
+}
diff --git a/test/fixedbugs/bug297.go b/test/fixedbugs/bug297.go
new file mode 100644
index 000000000..ba029427f
--- /dev/null
+++ b/test/fixedbugs/bug297.go
@@ -0,0 +1,15 @@
+// errchk $G $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.
+
+// Used to crash; issue 961.
+
+package main
+
+type ByteSize float64
+const (
+ _ = iota; // ignore first value by assigning to blank identifier
+ KB ByteSize = 1<<(10*X) // ERROR "undefined"
+)
diff --git a/test/fixedbugs/bug298.go b/test/fixedbugs/bug298.go
new file mode 100644
index 000000000..fe4a99a78
--- /dev/null
+++ b/test/fixedbugs/bug298.go
@@ -0,0 +1,11 @@
+// errchk $G $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.
+
+package ddd
+
+func Sum() int
+ for i := range []int{} { return i } // ERROR "return outside function|expected"
+
diff --git a/test/fixedbugs/bug299.go b/test/fixedbugs/bug299.go
new file mode 100644
index 000000000..4d7314432
--- /dev/null
+++ b/test/fixedbugs/bug299.go
@@ -0,0 +1,27 @@
+// errchk $G $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.
+
+package main
+
+type T struct {
+ // legal according to spec
+ x int
+ y (int)
+ int
+ *float
+ // not legal according to spec
+ (complex) // ERROR "non-declaration|expected|parenthesize"
+ (*string) // ERROR "non-declaration|expected|parenthesize"
+ *(bool) // ERROR "non-declaration|expected|parenthesize"
+}
+
+// legal according to spec
+func (p T) m() {}
+
+// not legal according to spec
+func (p (T)) f() {} // ERROR "parenthesize|expected"
+func (p *(T)) g() {} // ERROR "parenthesize|expected"
+func (p (*T)) h() {} // ERROR "parenthesize|expected"
diff --git a/test/fixedbugs/bug300.go b/test/fixedbugs/bug300.go
new file mode 100644
index 000000000..09ee3ab69
--- /dev/null
+++ b/test/fixedbugs/bug300.go
@@ -0,0 +1,29 @@
+// errchk $G $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.
+
+package main
+
+type T struct {
+ x, y *T
+}
+
+func main() {
+ // legal composite literals
+ _ = struct{}{}
+ _ = [42]int{}
+ _ = [...]int{}
+ _ = []int{}
+ _ = map[int]int{}
+ _ = T{}
+
+ // illegal composite literals: parentheses not allowed around literal type
+ _ = (struct{}){} // ERROR "parenthesize"
+ _ = ([42]int){} // ERROR "parenthesize"
+ _ = ([...]int){} // ERROR "parenthesize"
+ _ = ([]int){} // ERROR "parenthesize"
+ _ = (map[int]int){} // ERROR "parenthesize"
+ _ = (T){} // ERROR "parenthesize"
+}
diff --git a/test/fixedbugs/bug301.go b/test/fixedbugs/bug301.go
new file mode 100644
index 000000000..a58f4e13b
--- /dev/null
+++ b/test/fixedbugs/bug301.go
@@ -0,0 +1,18 @@
+// $G $D/$F.go || echo BUG: bug301.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.
+
+// http://code.google.com/p/go/issues/detail?id=990
+
+package main
+
+func main() {
+ defer func() {
+ if recover() != nil {
+ panic("non-nil recover")
+ }
+ }()
+ panic(nil)
+}
diff --git a/test/fixedbugs/bug302.dir/main.go b/test/fixedbugs/bug302.dir/main.go
new file mode 100644
index 000000000..9f874d08f
--- /dev/null
+++ b/test/fixedbugs/bug302.dir/main.go
@@ -0,0 +1,12 @@
+// 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
+
+// Check that the export information is correct in p.6.
+import _ "./p"
+
+// Check that it's still correct in pp.a (which contains p.6).
+import _ "./pp"
+
diff --git a/test/fixedbugs/bug302.dir/p.go b/test/fixedbugs/bug302.dir/p.go
new file mode 100644
index 000000000..7c54b906c
--- /dev/null
+++ b/test/fixedbugs/bug302.dir/p.go
@@ -0,0 +1,1011 @@
+// 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 p
+
+type T struct {
+ x1 int
+ x2 int
+ x3 int
+ x4 int
+ x5 int
+ x6 int
+ x7 int
+ x8 int
+ x9 int
+ x10 int
+ x11 int
+ x12 int
+ x13 int
+ x14 int
+ x15 int
+ x16 int
+ x17 int
+ x18 int
+ x19 int
+ x20 int
+ x21 int
+ x22 int
+ x23 int
+ x24 int
+ x25 int
+ x26 int
+ x27 int
+ x28 int
+ x29 int
+ x30 int
+ x31 int
+ x32 int
+ x33 int
+ x34 int
+ x35 int
+ x36 int
+ x37 int
+ x38 int
+ x39 int
+ x40 int
+ x41 int
+ x42 int
+ x43 int
+ x44 int
+ x45 int
+ x46 int
+ x47 int
+ x48 int
+ x49 int
+ x50 int
+ x51 int
+ x52 int
+ x53 int
+ x54 int
+ x55 int
+ x56 int
+ x57 int
+ x58 int
+ x59 int
+ x60 int
+ x61 int
+ x62 int
+ x63 int
+ x64 int
+ x65 int
+ x66 int
+ x67 int
+ x68 int
+ x69 int
+ x70 int
+ x71 int
+ x72 int
+ x73 int
+ x74 int
+ x75 int
+ x76 int
+ x77 int
+ x78 int
+ x79 int
+ x80 int
+ x81 int
+ x82 int
+ x83 int
+ x84 int
+ x85 int
+ x86 int
+ x87 int
+ x88 int
+ x89 int
+ x90 int
+ x91 int
+ x92 int
+ x93 int
+ x94 int
+ x95 int
+ x96 int
+ x97 int
+ x98 int
+ x99 int
+ x100 int
+ x101 int
+ x102 int
+ x103 int
+ x104 int
+ x105 int
+ x106 int
+ x107 int
+ x108 int
+ x109 int
+ x110 int
+ x111 int
+ x112 int
+ x113 int
+ x114 int
+ x115 int
+ x116 int
+ x117 int
+ x118 int
+ x119 int
+ x120 int
+ x121 int
+ x122 int
+ x123 int
+ x124 int
+ x125 int
+ x126 int
+ x127 int
+ x128 int
+ x129 int
+ x130 int
+ x131 int
+ x132 int
+ x133 int
+ x134 int
+ x135 int
+ x136 int
+ x137 int
+ x138 int
+ x139 int
+ x140 int
+ x141 int
+ x142 int
+ x143 int
+ x144 int
+ x145 int
+ x146 int
+ x147 int
+ x148 int
+ x149 int
+ x150 int
+ x151 int
+ x152 int
+ x153 int
+ x154 int
+ x155 int
+ x156 int
+ x157 int
+ x158 int
+ x159 int
+ x160 int
+ x161 int
+ x162 int
+ x163 int
+ x164 int
+ x165 int
+ x166 int
+ x167 int
+ x168 int
+ x169 int
+ x170 int
+ x171 int
+ x172 int
+ x173 int
+ x174 int
+ x175 int
+ x176 int
+ x177 int
+ x178 int
+ x179 int
+ x180 int
+ x181 int
+ x182 int
+ x183 int
+ x184 int
+ x185 int
+ x186 int
+ x187 int
+ x188 int
+ x189 int
+ x190 int
+ x191 int
+ x192 int
+ x193 int
+ x194 int
+ x195 int
+ x196 int
+ x197 int
+ x198 int
+ x199 int
+ x200 int
+ x201 int
+ x202 int
+ x203 int
+ x204 int
+ x205 int
+ x206 int
+ x207 int
+ x208 int
+ x209 int
+ x210 int
+ x211 int
+ x212 int
+ x213 int
+ x214 int
+ x215 int
+ x216 int
+ x217 int
+ x218 int
+ x219 int
+ x220 int
+ x221 int
+ x222 int
+ x223 int
+ x224 int
+ x225 int
+ x226 int
+ x227 int
+ x228 int
+ x229 int
+ x230 int
+ x231 int
+ x232 int
+ x233 int
+ x234 int
+ x235 int
+ x236 int
+ x237 int
+ x238 int
+ x239 int
+ x240 int
+ x241 int
+ x242 int
+ x243 int
+ x244 int
+ x245 int
+ x246 int
+ x247 int
+ x248 int
+ x249 int
+ x250 int
+ x251 int
+ x252 int
+ x253 int
+ x254 int
+ x255 int
+ x256 int
+ x257 int
+ x258 int
+ x259 int
+ x260 int
+ x261 int
+ x262 int
+ x263 int
+ x264 int
+ x265 int
+ x266 int
+ x267 int
+ x268 int
+ x269 int
+ x270 int
+ x271 int
+ x272 int
+ x273 int
+ x274 int
+ x275 int
+ x276 int
+ x277 int
+ x278 int
+ x279 int
+ x280 int
+ x281 int
+ x282 int
+ x283 int
+ x284 int
+ x285 int
+ x286 int
+ x287 int
+ x288 int
+ x289 int
+ x290 int
+ x291 int
+ x292 int
+ x293 int
+ x294 int
+ x295 int
+ x296 int
+ x297 int
+ x298 int
+ x299 int
+ x300 int
+ x301 int
+ x302 int
+ x303 int
+ x304 int
+ x305 int
+ x306 int
+ x307 int
+ x308 int
+ x309 int
+ x310 int
+ x311 int
+ x312 int
+ x313 int
+ x314 int
+ x315 int
+ x316 int
+ x317 int
+ x318 int
+ x319 int
+ x320 int
+ x321 int
+ x322 int
+ x323 int
+ x324 int
+ x325 int
+ x326 int
+ x327 int
+ x328 int
+ x329 int
+ x330 int
+ x331 int
+ x332 int
+ x333 int
+ x334 int
+ x335 int
+ x336 int
+ x337 int
+ x338 int
+ x339 int
+ x340 int
+ x341 int
+ x342 int
+ x343 int
+ x344 int
+ x345 int
+ x346 int
+ x347 int
+ x348 int
+ x349 int
+ x350 int
+ x351 int
+ x352 int
+ x353 int
+ x354 int
+ x355 int
+ x356 int
+ x357 int
+ x358 int
+ x359 int
+ x360 int
+ x361 int
+ x362 int
+ x363 int
+ x364 int
+ x365 int
+ x366 int
+ x367 int
+ x368 int
+ x369 int
+ x370 int
+ x371 int
+ x372 int
+ x373 int
+ x374 int
+ x375 int
+ x376 int
+ x377 int
+ x378 int
+ x379 int
+ x380 int
+ x381 int
+ x382 int
+ x383 int
+ x384 int
+ x385 int
+ x386 int
+ x387 int
+ x388 int
+ x389 int
+ x390 int
+ x391 int
+ x392 int
+ x393 int
+ x394 int
+ x395 int
+ x396 int
+ x397 int
+ x398 int
+ x399 int
+ x400 int
+ x401 int
+ x402 int
+ x403 int
+ x404 int
+ x405 int
+ x406 int
+ x407 int
+ x408 int
+ x409 int
+ x410 int
+ x411 int
+ x412 int
+ x413 int
+ x414 int
+ x415 int
+ x416 int
+ x417 int
+ x418 int
+ x419 int
+ x420 int
+ x421 int
+ x422 int
+ x423 int
+ x424 int
+ x425 int
+ x426 int
+ x427 int
+ x428 int
+ x429 int
+ x430 int
+ x431 int
+ x432 int
+ x433 int
+ x434 int
+ x435 int
+ x436 int
+ x437 int
+ x438 int
+ x439 int
+ x440 int
+ x441 int
+ x442 int
+ x443 int
+ x444 int
+ x445 int
+ x446 int
+ x447 int
+ x448 int
+ x449 int
+ x450 int
+ x451 int
+ x452 int
+ x453 int
+ x454 int
+ x455 int
+ x456 int
+ x457 int
+ x458 int
+ x459 int
+ x460 int
+ x461 int
+ x462 int
+ x463 int
+ x464 int
+ x465 int
+ x466 int
+ x467 int
+ x468 int
+ x469 int
+ x470 int
+ x471 int
+ x472 int
+ x473 int
+ x474 int
+ x475 int
+ x476 int
+ x477 int
+ x478 int
+ x479 int
+ x480 int
+ x481 int
+ x482 int
+ x483 int
+ x484 int
+ x485 int
+ x486 int
+ x487 int
+ x488 int
+ x489 int
+ x490 int
+ x491 int
+ x492 int
+ x493 int
+ x494 int
+ x495 int
+ x496 int
+ x497 int
+ x498 int
+ x499 int
+ x500 int
+ x501 int
+ x502 int
+ x503 int
+ x504 int
+ x505 int
+ x506 int
+ x507 int
+ x508 int
+ x509 int
+ x510 int
+ x511 int
+ x512 int
+ x513 int
+ x514 int
+ x515 int
+ x516 int
+ x517 int
+ x518 int
+ x519 int
+ x520 int
+ x521 int
+ x522 int
+ x523 int
+ x524 int
+ x525 int
+ x526 int
+ x527 int
+ x528 int
+ x529 int
+ x530 int
+ x531 int
+ x532 int
+ x533 int
+ x534 int
+ x535 int
+ x536 int
+ x537 int
+ x538 int
+ x539 int
+ x540 int
+ x541 int
+ x542 int
+ x543 int
+ x544 int
+ x545 int
+ x546 int
+ x547 int
+ x548 int
+ x549 int
+ x550 int
+ x551 int
+ x552 int
+ x553 int
+ x554 int
+ x555 int
+ x556 int
+ x557 int
+ x558 int
+ x559 int
+ x560 int
+ x561 int
+ x562 int
+ x563 int
+ x564 int
+ x565 int
+ x566 int
+ x567 int
+ x568 int
+ x569 int
+ x570 int
+ x571 int
+ x572 int
+ x573 int
+ x574 int
+ x575 int
+ x576 int
+ x577 int
+ x578 int
+ x579 int
+ x580 int
+ x581 int
+ x582 int
+ x583 int
+ x584 int
+ x585 int
+ x586 int
+ x587 int
+ x588 int
+ x589 int
+ x590 int
+ x591 int
+ x592 int
+ x593 int
+ x594 int
+ x595 int
+ x596 int
+ x597 int
+ x598 int
+ x599 int
+ x600 int
+ x601 int
+ x602 int
+ x603 int
+ x604 int
+ x605 int
+ x606 int
+ x607 int
+ x608 int
+ x609 int
+ x610 int
+ x611 int
+ x612 int
+ x613 int
+ x614 int
+ x615 int
+ x616 int
+ x617 int
+ x618 int
+ x619 int
+ x620 int
+ x621 int
+ x622 int
+ x623 int
+ x624 int
+ x625 int
+ x626 int
+ x627 int
+ x628 int
+ x629 int
+ x630 int
+ x631 int
+ x632 int
+ x633 int
+ x634 int
+ x635 int
+ x636 int
+ x637 int
+ x638 int
+ x639 int
+ x640 int
+ x641 int
+ x642 int
+ x643 int
+ x644 int
+ x645 int
+ x646 int
+ x647 int
+ x648 int
+ x649 int
+ x650 int
+ x651 int
+ x652 int
+ x653 int
+ x654 int
+ x655 int
+ x656 int
+ x657 int
+ x658 int
+ x659 int
+ x660 int
+ x661 int
+ x662 int
+ x663 int
+ x664 int
+ x665 int
+ x666 int
+ x667 int
+ x668 int
+ x669 int
+ x670 int
+ x671 int
+ x672 int
+ x673 int
+ x674 int
+ x675 int
+ x676 int
+ x677 int
+ x678 int
+ x679 int
+ x680 int
+ x681 int
+ x682 int
+ x683 int
+ x684 int
+ x685 int
+ x686 int
+ x687 int
+ x688 int
+ x689 int
+ x690 int
+ x691 int
+ x692 int
+ x693 int
+ x694 int
+ x695 int
+ x696 int
+ x697 int
+ x698 int
+ x699 int
+ x700 int
+ x701 int
+ x702 int
+ x703 int
+ x704 int
+ x705 int
+ x706 int
+ x707 int
+ x708 int
+ x709 int
+ x710 int
+ x711 int
+ x712 int
+ x713 int
+ x714 int
+ x715 int
+ x716 int
+ x717 int
+ x718 int
+ x719 int
+ x720 int
+ x721 int
+ x722 int
+ x723 int
+ x724 int
+ x725 int
+ x726 int
+ x727 int
+ x728 int
+ x729 int
+ x730 int
+ x731 int
+ x732 int
+ x733 int
+ x734 int
+ x735 int
+ x736 int
+ x737 int
+ x738 int
+ x739 int
+ x740 int
+ x741 int
+ x742 int
+ x743 int
+ x744 int
+ x745 int
+ x746 int
+ x747 int
+ x748 int
+ x749 int
+ x750 int
+ x751 int
+ x752 int
+ x753 int
+ x754 int
+ x755 int
+ x756 int
+ x757 int
+ x758 int
+ x759 int
+ x760 int
+ x761 int
+ x762 int
+ x763 int
+ x764 int
+ x765 int
+ x766 int
+ x767 int
+ x768 int
+ x769 int
+ x770 int
+ x771 int
+ x772 int
+ x773 int
+ x774 int
+ x775 int
+ x776 int
+ x777 int
+ x778 int
+ x779 int
+ x780 int
+ x781 int
+ x782 int
+ x783 int
+ x784 int
+ x785 int
+ x786 int
+ x787 int
+ x788 int
+ x789 int
+ x790 int
+ x791 int
+ x792 int
+ x793 int
+ x794 int
+ x795 int
+ x796 int
+ x797 int
+ x798 int
+ x799 int
+ x800 int
+ x801 int
+ x802 int
+ x803 int
+ x804 int
+ x805 int
+ x806 int
+ x807 int
+ x808 int
+ x809 int
+ x810 int
+ x811 int
+ x812 int
+ x813 int
+ x814 int
+ x815 int
+ x816 int
+ x817 int
+ x818 int
+ x819 int
+ x820 int
+ x821 int
+ x822 int
+ x823 int
+ x824 int
+ x825 int
+ x826 int
+ x827 int
+ x828 int
+ x829 int
+ x830 int
+ x831 int
+ x832 int
+ x833 int
+ x834 int
+ x835 int
+ x836 int
+ x837 int
+ x838 int
+ x839 int
+ x840 int
+ x841 int
+ x842 int
+ x843 int
+ x844 int
+ x845 int
+ x846 int
+ x847 int
+ x848 int
+ x849 int
+ x850 int
+ x851 int
+ x852 int
+ x853 int
+ x854 int
+ x855 int
+ x856 int
+ x857 int
+ x858 int
+ x859 int
+ x860 int
+ x861 int
+ x862 int
+ x863 int
+ x864 int
+ x865 int
+ x866 int
+ x867 int
+ x868 int
+ x869 int
+ x870 int
+ x871 int
+ x872 int
+ x873 int
+ x874 int
+ x875 int
+ x876 int
+ x877 int
+ x878 int
+ x879 int
+ x880 int
+ x881 int
+ x882 int
+ x883 int
+ x884 int
+ x885 int
+ x886 int
+ x887 int
+ x888 int
+ x889 int
+ x890 int
+ x891 int
+ x892 int
+ x893 int
+ x894 int
+ x895 int
+ x896 int
+ x897 int
+ x898 int
+ x899 int
+ x900 int
+ x901 int
+ x902 int
+ x903 int
+ x904 int
+ x905 int
+ x906 int
+ x907 int
+ x908 int
+ x909 int
+ x910 int
+ x911 int
+ x912 int
+ x913 int
+ x914 int
+ x915 int
+ x916 int
+ x917 int
+ x918 int
+ x919 int
+ x920 int
+ x921 int
+ x922 int
+ x923 int
+ x924 int
+ x925 int
+ x926 int
+ x927 int
+ x928 int
+ x929 int
+ x930 int
+ x931 int
+ x932 int
+ x933 int
+ x934 int
+ x935 int
+ x936 int
+ x937 int
+ x938 int
+ x939 int
+ x940 int
+ x941 int
+ x942 int
+ x943 int
+ x944 int
+ x945 int
+ x946 int
+ x947 int
+ x948 int
+ x949 int
+ x950 int
+ x951 int
+ x952 int
+ x953 int
+ x954 int
+ x955 int
+ x956 int
+ x957 int
+ x958 int
+ x959 int
+ x960 int
+ x961 int
+ x962 int
+ x963 int
+ x964 int
+ x965 int
+ x966 int
+ x967 int
+ x968 int
+ x969 int
+ x970 int
+ x971 int
+ x972 int
+ x973 int
+ x974 int
+ x975 int
+ x976 int
+ x977 int
+ x978 int
+ x979 int
+ x980 int
+ x981 int
+ x982 int
+ x983 int
+ x984 int
+ x985 int
+ x986 int
+ x987 int
+ x988 int
+ x989 int
+ x990 int
+ x991 int
+ x992 int
+ x993 int
+ x994 int
+ x995 int
+ x996 int
+ x997 int
+ x998 int
+ x999 int
+ x1000 int
+}
+
+func (t *T) M() {
+}
diff --git a/test/fixedbugs/bug302.go b/test/fixedbugs/bug302.go
new file mode 100644
index 000000000..e9edb94ac
--- /dev/null
+++ b/test/fixedbugs/bug302.go
@@ -0,0 +1,6 @@
+// $G $D/bug302.dir/p.go && gopack grc pp.a p.$A && $G $D/bug302.dir/main.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.
+
diff --git a/test/fixedbugs/bug303.go b/test/fixedbugs/bug303.go
new file mode 100644
index 000000000..3bd790f13
--- /dev/null
+++ b/test/fixedbugs/bug303.go
@@ -0,0 +1,37 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+// Issue 1011. Removing either #1 or #3 avoided the crash at #2.
+
+package main
+
+import (
+ "io"
+ "strings"
+)
+
+func readU16BE(b []byte) uint16 {
+ b[0] = 0
+ b[1] = 1
+ return uint16(b[0])<<8 + uint16(b[1]) // #1
+ n := uint16(b[0])<<8 + uint16(b[1])
+ return n
+}
+
+func readStr(r io.Reader, b []byte) string {
+ n := readU16BE(b)
+ if int(n) > len(b) {
+ return "err: n>b"
+ }
+ io.ReadFull(r, b[0:n]) // #2
+ return string(b[0:n]) // #3
+ return "ok"
+}
+
+func main() {
+ br := strings.NewReader("abcd")
+ readStr(br, make([]byte, 256))
+}
diff --git a/test/fixedbugs/bug304.go b/test/fixedbugs/bug304.go
new file mode 100644
index 000000000..adcf08a35
--- /dev/null
+++ b/test/fixedbugs/bug304.go
@@ -0,0 +1,18 @@
+// $G $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.
+
+// Caused a gccgo crash on compilation.
+// bug304.go: In function ‘p.f’:
+// bug304.go:15:2: internal compiler error: in copy_tree_r, at tree-inline.c:4114
+
+package p
+type S struct {
+ v interface{}
+}
+func g(e interface{}) { }
+func f(s S) {
+ g(s.v.(*int))
+}
diff --git a/test/fixedbugs/bug305.go b/test/fixedbugs/bug305.go
new file mode 100644
index 000000000..758fee269
--- /dev/null
+++ b/test/fixedbugs/bug305.go
@@ -0,0 +1,24 @@
+// errchk $G $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.
+
+// Use //line to set the line number of the next line to 20.
+//line fixedbugs/bug305.go:20
+
+package p
+
+// Introduce an error which should be reported on line 24.
+var a int = "bogus"
+
+// Line 15 of file.
+// 16
+// 17
+// 18
+// 19
+// 20
+// 21
+// 22
+// 23
+// ERROR "cannot|incompatible"
diff --git a/test/fixedbugs/bug306.dir/p1.go b/test/fixedbugs/bug306.dir/p1.go
new file mode 100644
index 000000000..bf87ea149
--- /dev/null
+++ b/test/fixedbugs/bug306.dir/p1.go
@@ -0,0 +1,9 @@
+// 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 p1
+
+type T <-chan int
+var x = make(chan T)
+
diff --git a/test/fixedbugs/bug306.dir/p2.go b/test/fixedbugs/bug306.dir/p2.go
new file mode 100644
index 000000000..3f8bd9d49
--- /dev/null
+++ b/test/fixedbugs/bug306.dir/p2.go
@@ -0,0 +1,8 @@
+// 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 p2
+
+import _ "./p1"
+
diff --git a/test/fixedbugs/bug306.go b/test/fixedbugs/bug306.go
new file mode 100644
index 000000000..a0a43507d
--- /dev/null
+++ b/test/fixedbugs/bug306.go
@@ -0,0 +1,7 @@
+// $G $D/$F.dir/p1.go && $G $D/$F.dir/p2.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.
+
+ignored
diff --git a/test/fixedbugs/bug307.go b/test/fixedbugs/bug307.go
new file mode 100644
index 000000000..a1a30dfb7
--- /dev/null
+++ b/test/fixedbugs/bug307.go
@@ -0,0 +1,15 @@
+// $G $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.
+
+// Valid program, gccgo reported an error.
+// bug307.go:14:6: error: cmplx arguments must have identical types
+
+package main
+
+func main() {
+ var f float64
+ _ = cmplx(1 / f, 0)
+}
diff --git a/test/fixedbugs/bug308.go b/test/fixedbugs/bug308.go
new file mode 100644
index 000000000..c2845f042
--- /dev/null
+++ b/test/fixedbugs/bug308.go
@@ -0,0 +1,19 @@
+// $G $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.
+
+// issue 1136
+
+package main
+
+import "fmt"
+
+func log1(f string, argv ...interface{}) {
+ fmt.Printf("log: %s\n", fmt.Sprintf(f, argv...))
+}
+
+func main() {
+ log1("%d", 42)
+}
diff --git a/test/fixedbugs/bug309.go b/test/fixedbugs/bug309.go
new file mode 100644
index 000000000..07bebae74
--- /dev/null
+++ b/test/fixedbugs/bug309.go
@@ -0,0 +1,19 @@
+// $G $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.
+
+// issue 1016
+
+package main
+
+func foo(t interface{}, c chan int) {
+ switch v := t.(type) {
+ case int:
+ select {
+ case <-c:
+ // bug was: internal compiler error: var without type, init: v
+ }
+ }
+}
diff --git a/test/fixedbugs/bug310.go b/test/fixedbugs/bug310.go
new file mode 100644
index 000000000..191f3ed2b
--- /dev/null
+++ b/test/fixedbugs/bug310.go
@@ -0,0 +1,20 @@
+// errchk $G $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.
+
+package p
+
+import (
+ "bytes"
+ "fmt"
+)
+
+type t int
+
+func main() {
+ _ = t.bar // ERROR "no method"
+ var b bytes.Buffer
+ fmt.Print(b) // ERROR "implicit assignment"
+}
diff --git a/test/fixedbugs/bug311.go b/test/fixedbugs/bug311.go
new file mode 100644
index 000000000..ed937a674
--- /dev/null
+++ b/test/fixedbugs/bug311.go
@@ -0,0 +1,20 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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() {
+ m := make(map[string][1000]byte)
+ m["hi"] = [1000]byte{1}
+
+ v := m["hi"]
+
+ for k, vv := range m {
+ if k != "hi" || string(v[:]) != string(vv[:]) {
+ panic("bad iter")
+ }
+ }
+}
diff --git a/test/fixedbugs/bug312.go b/test/fixedbugs/bug312.go
new file mode 100644
index 000000000..70888dd41
--- /dev/null
+++ b/test/fixedbugs/bug312.go
@@ -0,0 +1,22 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+// issue 1172
+
+package main
+
+func main() {
+ var i interface{}
+ c := make(chan int, 1)
+ c <- 1
+ select {
+ case i = <-c: // error on this line
+ }
+ if i != 1 {
+ println("bad i", i)
+ panic("BUG")
+ }
+}
diff --git a/test/fixedbugs/bug313.dir/a.go b/test/fixedbugs/bug313.dir/a.go
new file mode 100644
index 000000000..cb4ca7256
--- /dev/null
+++ b/test/fixedbugs/bug313.dir/a.go
@@ -0,0 +1,11 @@
+// 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"
+
+func a() {
+ fmt.DoesNotExist() // ERROR "undefined"
+}
diff --git a/test/fixedbugs/bug313.dir/b.go b/test/fixedbugs/bug313.dir/b.go
new file mode 100644
index 000000000..7eda72b4f
--- /dev/null
+++ b/test/fixedbugs/bug313.dir/b.go
@@ -0,0 +1,11 @@
+// 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"
+
+func b() {
+ Println()
+}
diff --git a/test/fixedbugs/bug313.go b/test/fixedbugs/bug313.go
new file mode 100644
index 000000000..eb2a0223b
--- /dev/null
+++ b/test/fixedbugs/bug313.go
@@ -0,0 +1,19 @@
+// errchk $G -e $D/$F.dir/[ab].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.
+
+// Issue 1284
+
+package bug313
+
+/*
+6g bug313.dir/[ab].go
+
+Before:
+bug313.dir/b.go:7: internal compiler error: fault
+
+Now:
+bug313.dir/a.go:10: undefined: fmt.DoesNotExist
+*/
diff --git a/test/fixedbugs/bug314.go b/test/fixedbugs/bug314.go
new file mode 100644
index 000000000..95d81d795
--- /dev/null
+++ b/test/fixedbugs/bug314.go
@@ -0,0 +1,31 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug314
+
+// 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.
+
+// Used to call wrong methods; issue 1290.
+
+package main
+
+type S struct {
+}
+func (S) a() int{
+ return 0
+}
+func (S) b() int{
+ return 1
+}
+
+func main() {
+ var i interface {
+ b() int
+ a() int
+ } = S{}
+ if i.a() != 0 {
+ panic("wrong method called")
+ }
+ if i.b() != 1 {
+ panic("wrong method called")
+ }
+}
diff --git a/test/fixedbugs/bug315.go b/test/fixedbugs/bug315.go
new file mode 100644
index 000000000..198bae77a
--- /dev/null
+++ b/test/fixedbugs/bug315.go
@@ -0,0 +1,18 @@
+// $G $D/$F.go || echo BUG: bug315
+
+// 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.
+
+// Issue 1368.
+
+package main
+
+func main() {
+ a := cmplx(2, 2)
+ a /= 2
+}
+
+/*
+bug315.go:13: internal compiler error: optoas: no entry DIV-complex
+*/
diff --git a/test/fixedbugs/bug316.go b/test/fixedbugs/bug316.go
new file mode 100644
index 000000000..bd4d99eb6
--- /dev/null
+++ b/test/fixedbugs/bug316.go
@@ -0,0 +1,17 @@
+// $G $D/$F.go || echo BUG: bug316
+
+// 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.
+
+// Issue 1369.
+
+package main
+
+const (
+ c = cmplx(1, 2)
+ r = real(c) // was: const initializer must be constant
+ i = imag(c) // was: const initializer must be constant
+)
+
+func main() {}
diff --git a/test/fixedbugs/bug317.go b/test/fixedbugs/bug317.go
new file mode 100644
index 000000000..0cb26c29b
--- /dev/null
+++ b/test/fixedbugs/bug317.go
@@ -0,0 +1,16 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug317
+
+// 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() {
+ x := []uint{0}
+ x[0] &^= f()
+}
+
+func f() uint {
+ return 1<<31 // doesn't panic with 1<<31 - 1
+}
diff --git a/test/float_lit.go b/test/float_lit.go
index 58bd4dac0..7b91d88e5 100644
--- a/test/float_lit.go
+++ b/test/float_lit.go
@@ -6,96 +6,192 @@
package main
-func
-pow10(pow int) float64 {
- if pow < 0 { return 1/pow10(-pow); }
- if pow > 0 { return pow10(pow-1)*10; }
- return 1;
+var bad bool
+
+func pow10(pow int) float64 {
+ if pow < 0 {
+ return 1 / pow10(-pow)
+ }
+ if pow > 0 {
+ return pow10(pow-1) * 10
+ }
+ return 1
}
-func
-close(da float64, ia, ib int64, pow int) bool {
- db := float64(ia) / float64(ib);
- db *= pow10(pow);
+func close(da float64, ia, ib int64, pow int) bool {
+ db := float64(ia) / float64(ib)
+ db *= pow10(pow)
if da == 0 || db == 0 {
if da == 0 && db == 0 {
- return true;
+ return true
}
- return false;
+ return false
}
- de := (da-db) /da;
+ de := (da - db) / da
if de < 0 {
- de = -de;
+ de = -de
}
- if de < 1.0e-14 {
- return true;
+ if de < 1e-14 {
+ return true
+ }
+ if !bad {
+ println("BUG")
+ bad = true
}
- return false;
+ return false
}
-func
-main() {
-
- if !close(0., 0, 1, 0) { print("0. is ", 0., "\n"); }
- if !close(+10., 10, 1, 0) { print("+10. is ", +10., "\n"); }
- if !close(-210., -210, 1, 0) { print("-210. is ", -210., "\n"); }
+func main() {
+ if !close(0., 0, 1, 0) {
+ print("0. is ", 0., "\n")
+ }
+ if !close(+10., 10, 1, 0) {
+ print("+10. is ", +10., "\n")
+ }
+ if !close(-210., -210, 1, 0) {
+ print("-210. is ", -210., "\n")
+ }
- if !close(.0, 0, 1, 0) { print(".0 is ", .0, "\n"); }
- if !close(+.01, 1, 100, 0) { print("+.01 is ", +.01, "\n"); }
- if !close(-.012, -12, 1000, 0) { print("-.012 is ", -.012, "\n"); }
+ if !close(.0, 0, 1, 0) {
+ print(".0 is ", .0, "\n")
+ }
+ if !close(+.01, 1, 100, 0) {
+ print("+.01 is ", +.01, "\n")
+ }
+ if !close(-.012, -12, 1000, 0) {
+ print("-.012 is ", -.012, "\n")
+ }
- if !close(0.0, 0, 1, 0) { print("0.0 is ", 0.0, "\n"); }
- if !close(+10.01, 1001, 100, 0) { print("+10.01 is ", +10.01, "\n"); }
- if !close(-210.012, -210012, 1000, 0) { print("-210.012 is ", -210.012, "\n"); }
+ if !close(0.0, 0, 1, 0) {
+ print("0.0 is ", 0.0, "\n")
+ }
+ if !close(+10.01, 1001, 100, 0) {
+ print("+10.01 is ", +10.01, "\n")
+ }
+ if !close(-210.012, -210012, 1000, 0) {
+ print("-210.012 is ", -210.012, "\n")
+ }
- if !close(0E+1, 0, 1, 0) { print("0E+1 is ", 0E+1, "\n"); }
- if !close(+10e2, 10, 1, 2) { print("+10e2 is ", +10e2, "\n"); }
- if !close(-210e3, -210, 1, 3) { print("-210e3 is ", -210e3, "\n"); }
+ if !close(0E+1, 0, 1, 0) {
+ print("0E+1 is ", 0E+1, "\n")
+ }
+ if !close(+10e2, 10, 1, 2) {
+ print("+10e2 is ", +10e2, "\n")
+ }
+ if !close(-210e3, -210, 1, 3) {
+ print("-210e3 is ", -210e3, "\n")
+ }
- if !close(0E-1, 0, 1, 0) { print("0E-1 is ", 0E-1, "\n"); }
- if !close(+0e23, 0, 1, 1) { print("+0e23 is ", +0e23, "\n"); }
- if !close(-0e345, 0, 1, 1) { print("-0e345 is ", -0e345, "\n"); }
+ if !close(0E-1, 0, 1, 0) {
+ print("0E-1 is ", 0E-1, "\n")
+ }
+ if !close(+0e23, 0, 1, 1) {
+ print("+0e23 is ", +0e23, "\n")
+ }
+ if !close(-0e345, 0, 1, 1) {
+ print("-0e345 is ", -0e345, "\n")
+ }
- if !close(0E1, 0, 1, 1) { print("0E1 is ", 0E1, "\n"); }
- if !close(+10e23, 10, 1, 23) { print("+10e23 is ", +10e23, "\n"); }
- if !close(-210e34, -210, 1, 34) { print("-210e34 is ", -210e34, "\n"); }
+ if !close(0E1, 0, 1, 1) {
+ print("0E1 is ", 0E1, "\n")
+ }
+ if !close(+10e23, 10, 1, 23) {
+ print("+10e23 is ", +10e23, "\n")
+ }
+ if !close(-210e34, -210, 1, 34) {
+ print("-210e34 is ", -210e34, "\n")
+ }
- if !close(0.E1, 0, 1, 1) { print("0.E1 is ", 0.E1, "\n"); }
- if !close(+10.e+2, 10, 1, 2) { print("+10.e+2 is ", +10.e+2, "\n"); }
- if !close(-210.e-3, -210, 1, -3) { print("-210.e-3 is ", -210.e-3, "\n"); }
+ if !close(0.E1, 0, 1, 1) {
+ print("0.E1 is ", 0.E1, "\n")
+ }
+ if !close(+10.e+2, 10, 1, 2) {
+ print("+10.e+2 is ", +10.e+2, "\n")
+ }
+ if !close(-210.e-3, -210, 1, -3) {
+ print("-210.e-3 is ", -210.e-3, "\n")
+ }
- if !close(.0E1, 0, 1, 1) { print(".0E1 is ", .0E1, "\n"); }
- if !close(+.01e2, 1, 100, 2) { print("+.01e2 is ", +.01e2, "\n"); }
- if !close(-.012e3, -12, 1000, 3) { print("-.012e3 is ", -.012e3, "\n"); }
+ if !close(.0E1, 0, 1, 1) {
+ print(".0E1 is ", .0E1, "\n")
+ }
+ if !close(+.01e2, 1, 100, 2) {
+ print("+.01e2 is ", +.01e2, "\n")
+ }
+ if !close(-.012e3, -12, 1000, 3) {
+ print("-.012e3 is ", -.012e3, "\n")
+ }
- if !close(0.0E1, 0, 1, 0) { print("0.0E1 is ", 0.0E1, "\n"); }
- if !close(+10.01e2, 1001, 100, 2) { print("+10.01e2 is ", +10.01e2, "\n"); }
- if !close(-210.012e3, -210012, 1000, 3) { print("-210.012e3 is ", -210.012e3, "\n"); }
+ if !close(0.0E1, 0, 1, 0) {
+ print("0.0E1 is ", 0.0E1, "\n")
+ }
+ if !close(+10.01e2, 1001, 100, 2) {
+ print("+10.01e2 is ", +10.01e2, "\n")
+ }
+ if !close(-210.012e3, -210012, 1000, 3) {
+ print("-210.012e3 is ", -210.012e3, "\n")
+ }
- if !close(0.E+12, 0, 1, 0) { print("0.E+12 is ", 0.E+12, "\n"); }
- if !close(+10.e23, 10, 1, 23) { print("+10.e23 is ", +10.e23, "\n"); }
- if !close(-210.e33, -210, 1, 33) { print("-210.e33 is ", -210.e33, "\n"); }
+ if !close(0.E+12, 0, 1, 0) {
+ print("0.E+12 is ", 0.E+12, "\n")
+ }
+ if !close(+10.e23, 10, 1, 23) {
+ print("+10.e23 is ", +10.e23, "\n")
+ }
+ if !close(-210.e33, -210, 1, 33) {
+ print("-210.e33 is ", -210.e33, "\n")
+ }
- if !close(.0E-12, 0, 1, 0) { print(".0E-12 is ", .0E-12, "\n"); }
- if !close(+.01e23, 1, 100, 23) { print("+.01e23 is ", +.01e23, "\n"); }
- if !close(-.012e34, -12, 1000, 34) { print("-.012e34 is ", -.012e34, "\n"); }
+ if !close(.0E-12, 0, 1, 0) {
+ print(".0E-12 is ", .0E-12, "\n")
+ }
+ if !close(+.01e23, 1, 100, 23) {
+ print("+.01e23 is ", +.01e23, "\n")
+ }
+ if !close(-.012e34, -12, 1000, 34) {
+ print("-.012e34 is ", -.012e34, "\n")
+ }
- if !close(0.0E12, 0, 1, 12) { print("0.0E12 is ", 0.0E12, "\n"); }
- if !close(+10.01e23, 1001, 100, 23) { print("+10.01e23 is ", +10.01e23, "\n"); }
- if !close(-210.012e33, -210012, 1000, 33) { print("-210.012e33 is ", -210.012e33, "\n"); }
+ if !close(0.0E12, 0, 1, 12) {
+ print("0.0E12 is ", 0.0E12, "\n")
+ }
+ if !close(+10.01e23, 1001, 100, 23) {
+ print("+10.01e23 is ", +10.01e23, "\n")
+ }
+ if !close(-210.012e33, -210012, 1000, 33) {
+ print("-210.012e33 is ", -210.012e33, "\n")
+ }
- if !close(0.E123, 0, 1, 123) { print("0.E123 is ", 0.E123, "\n"); }
- if !close(+10.e+23, 10, 1, 23) { print("+10.e+234 is ", +10.e+234, "\n"); }
- if !close(-210.e-35, -210, 1, -35) { print("-210.e-35 is ", -210.e-35, "\n"); }
+ if !close(0.E123, 0, 1, 123) {
+ print("0.E123 is ", 0.E123, "\n")
+ }
+ if !close(+10.e+23, 10, 1, 23) {
+ print("+10.e+234 is ", +10.e+234, "\n")
+ }
+ if !close(-210.e-35, -210, 1, -35) {
+ print("-210.e-35 is ", -210.e-35, "\n")
+ }
- if !close(.0E123, 0, 1, 123) { print(".0E123 is ", .0E123, "\n"); }
- if !close(+.01e29, 1, 100, 29) { print("+.01e29 is ", +.01e29, "\n"); }
- if !close(-.012e29, -12, 1000, 29) { print("-.012e29 is ", -.012e29, "\n"); }
+ if !close(.0E123, 0, 1, 123) {
+ print(".0E123 is ", .0E123, "\n")
+ }
+ if !close(+.01e29, 1, 100, 29) {
+ print("+.01e29 is ", +.01e29, "\n")
+ }
+ if !close(-.012e29, -12, 1000, 29) {
+ print("-.012e29 is ", -.012e29, "\n")
+ }
- if !close(0.0E123, 0, 1, 123) { print("0.0E123 is ", 0.0E123, "\n"); }
- if !close(+10.01e31, 1001, 100, 31) { print("+10.01e31 is ", +10.01e31, "\n"); }
- if !close(-210.012e19, -210012, 1000, 19) { print("-210.012e19 is ", -210.012e19, "\n"); }
+ if !close(0.0E123, 0, 1, 123) {
+ print("0.0E123 is ", 0.0E123, "\n")
+ }
+ if !close(+10.01e31, 1001, 100, 31) {
+ print("+10.01e31 is ", +10.01e31, "\n")
+ }
+ if !close(-210.012e19, -210012, 1000, 19) {
+ print("-210.012e19 is ", -210.012e19, "\n")
+ }
}
diff --git a/test/floatcmp.go b/test/floatcmp.go
index 26fc6ad14..f51cbc277 100644
--- a/test/floatcmp.go
+++ b/test/floatcmp.go
@@ -9,13 +9,13 @@ package main
import "math"
type floatTest struct {
- name string;
- expr bool;
- want bool;
+ name string
+ expr bool
+ want bool
}
-var nan float64 = math.NaN();
-var f float64 = 1;
+var nan float64 = math.NaN()
+var f float64 = 1
var tests = []floatTest{
floatTest{"nan == nan", nan == nan, false},
@@ -75,14 +75,14 @@ var tests = []floatTest{
}
func main() {
- bad := false;
+ bad := false
for _, t := range tests {
if t.expr != t.want {
if !bad {
- bad = true;
- println("BUG: floatcmp");
+ bad = true
+ println("BUG: floatcmp")
}
- println(t.name, "=", t.expr, "want", t.want);
+ println(t.name, "=", t.expr, "want", t.want)
}
}
}
diff --git a/test/for.go b/test/for.go
index 05260ff88..36ad15709 100644
--- a/test/for.go
+++ b/test/for.go
@@ -8,49 +8,49 @@ package main
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
- print("assertion fail", msg, "\n");
- panic(1);
+ print("assertion fail", msg, "\n")
+ panic(1)
}
}
func main() {
- var i, sum int;
+ var i, sum int
- i = 0;
+ i = 0
for {
- i = i + 1;
+ i = i + 1
if i > 5 {
- break;
+ break
}
}
- assertequal(i, 6, "break");
+ assertequal(i, 6, "break")
- sum = 0;
+ sum = 0
for i := 0; i <= 10; i++ {
- sum = sum + i;
+ sum = sum + i
}
- assertequal(sum, 55, "all three");
+ assertequal(sum, 55, "all three")
- sum = 0;
+ sum = 0
for i := 0; i <= 10; {
- sum = sum + i;
- i++;
+ sum = sum + i
+ i++
}
- assertequal(sum, 55, "only two");
+ assertequal(sum, 55, "only two")
- sum = 0;
+ sum = 0
for sum < 100 {
- sum = sum + 9;
+ sum = sum + 9
}
- assertequal(sum, 99 + 9, "only one");
+ assertequal(sum, 99 + 9, "only one")
- sum = 0;
+ sum = 0
for i := 0; i <= 10; i++ {
if i % 2 == 0 {
- continue;
+ continue
}
- sum = sum + i;
+ sum = sum + i
}
- assertequal(sum, 1+3+5+7+9, "continue");
+ assertequal(sum, 1+3+5+7+9, "continue")
}
diff --git a/test/func.go b/test/func.go
index ee9414ddc..0c1a07979 100644
--- a/test/func.go
+++ b/test/func.go
@@ -9,8 +9,8 @@ package main
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
- print("assertion fail", msg, "\n");
- panic(1);
+ print("assertion fail", msg, "\n")
+ panic(1)
}
}
@@ -21,69 +21,69 @@ func f2(a int) {
}
func f3(a, b int) int {
- return a+b;
+ return a+b
}
func f4(a, b int, c float) int {
- return (a+b)/2 + int(c);
+ return (a+b)/2 + int(c)
}
func f5(a int) int {
- return 5;
+ return 5
}
func f6(a int) (r int) {
- return 6;
+ return 6
}
func f7(a int) (x int, y float) {
- return 7, 7.0;
+ return 7, 7.0
}
func f8(a int) (x int, y float) {
- return 8, 8.0;
+ return 8, 8.0
}
type T struct {
- x, y int;
+ x, y int
}
func (t *T) m10(a int, b float) int {
- return (t.x+a) * (t.y+int(b));
+ return (t.x+a) * (t.y+int(b))
}
func f9(a int) (i int, f float) {
- i = 9;
- f = 9.0;
- return;
+ i = 9
+ f = 9.0
+ return
}
func main() {
- f1();
- f2(1);
- r3 := f3(1, 2);
- assertequal(r3, 3, "3");
- r4 := f4(0, 2, 3.0);
- assertequal(r4, 4, "4");
- r5 := f5(1);
- assertequal(r5, 5, "5");
- r6 := f6(1);
- assertequal(r6, 6, "6");
- r7, s7 := f7(1);
- assertequal(r7, 7, "r7");
- assertequal(int(s7), 7, "s7");
- r8, s8 := f8(1);
- assertequal(r8, 8, "r8");
- assertequal(int(s8), 8, "s8");
- r9, s9 := f9(1);
- assertequal(r9, 9, "r9");
- assertequal(int(s9), 9, "s9");
- var t *T = new(T);
- t.x = 1;
- t.y = 2;
- r10 := t.m10(1, 3.0);
- assertequal(r10, 10, "10");
+ f1()
+ f2(1)
+ r3 := f3(1, 2)
+ assertequal(r3, 3, "3")
+ r4 := f4(0, 2, 3.0)
+ assertequal(r4, 4, "4")
+ r5 := f5(1)
+ assertequal(r5, 5, "5")
+ r6 := f6(1)
+ assertequal(r6, 6, "6")
+ r7, s7 := f7(1)
+ assertequal(r7, 7, "r7")
+ assertequal(int(s7), 7, "s7")
+ r8, s8 := f8(1)
+ assertequal(r8, 8, "r8")
+ assertequal(int(s8), 8, "s8")
+ r9, s9 := f9(1)
+ assertequal(r9, 9, "r9")
+ assertequal(int(s9), 9, "s9")
+ var t *T = new(T)
+ t.x = 1
+ t.y = 2
+ r10 := t.m10(1, 3.0)
+ assertequal(r10, 10, "10")
}
diff --git a/test/func1.go b/test/func1.go
index 2c767d21d..56f4dfcba 100644
--- a/test/func1.go
+++ b/test/func1.go
@@ -9,10 +9,10 @@
package main
func f1(a int) (int, float) { // BUG (not caught by compiler): multiple return values must have names
- return 7, 7.0;
+ return 7, 7.0
}
func f2(a int) (a int, b float) { // ERROR "redeclared|definition"
- return 8, 8.0;
+ return 8, 8.0
}
diff --git a/test/func2.go b/test/func2.go
index e8e6842e0..5a6d7d0e1 100644
--- a/test/func2.go
+++ b/test/func2.go
@@ -5,20 +5,20 @@
// license that can be found in the LICENSE file.
package main
-import os "os";
+import os "os"
-type t1 int;
-type t2 int;
-type t3 int;
+type t1 int
+type t2 int
+type t3 int
-func f1(t1, t2, t3);
-func f2(t1, t2, t3 bool);
-func f3(t1, t2, x t3);
-func f4(t1, *t3);
-func (x *t1) f5(y []t2) (t1, *t3);
-func f6() (int, *string);
-func f7(*t2, t3);
-func f8(os int) int;
+func f1(t1, t2, t3)
+func f2(t1, t2, t3 bool)
+func f3(t1, t2, x t3)
+func f4(t1, *t3)
+func (x *t1) f5(y []t2) (t1, *t3)
+func f6() (int, *string)
+func f7(*t2, t3)
+func f8(os int) int
func f9(os int) int {
return os
diff --git a/test/func3.go b/test/func3.go
index 33e80a716..110b0ef1c 100644
--- a/test/func3.go
+++ b/test/func3.go
@@ -6,12 +6,12 @@
package main
-type t1 int;
-type t2 int;
-type t3 int;
+type t1 int
+type t2 int
+type t3 int
-func f1(*t2, x t3); // ERROR "named"
-func f2(t1, *t2, x t3); // ERROR "named"
-func f3() (x int, *string); // ERROR "named"
+func f1(*t2, x t3) // ERROR "named"
+func f2(t1, *t2, x t3) // ERROR "named"
+func f3() (x int, *string) // ERROR "named"
-func f4() (t1 t1); // legal - scope of parameter named t1 starts in body of f4.
+func f4() (t1 t1) // legal - scope of parameter named t1 starts in body of f4.
diff --git a/test/func4.go b/test/func4.go
index bcf5b93fa..69ce56a19 100644
--- a/test/func4.go
+++ b/test/func4.go
@@ -9,6 +9,6 @@ package main
var notmain func()
func main() {
- var x = &main; // ERROR "address of|invalid"
- main = notmain; // ERROR "assign to|invalid"
+ var x = &main // ERROR "address of|invalid"
+ main = notmain // ERROR "assign to|invalid"
}
diff --git a/test/garbage/Makefile b/test/garbage/Makefile
index 1a5062b44..ab29e0956 100644
--- a/test/garbage/Makefile
+++ b/test/garbage/Makefile
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-include ../../src/Make.$(GOARCH)
+include ../../src/Make.inc
ALL=\
parser\
diff --git a/test/garbage/parser.go b/test/garbage/parser.go
index e8e049474..cf68737fb 100644
--- a/test/garbage/parser.go
+++ b/test/garbage/parser.go
@@ -30,11 +30,11 @@ func isPkgFile(dir *os.FileInfo) bool {
}
func pkgName(filename string) string {
- file, err := parser.ParseFile(filename, nil, nil, parser.PackageClauseOnly)
+ file, err := parser.ParseFile(filename, nil, parser.PackageClauseOnly)
if err != nil || file == nil {
return ""
}
- return file.Name.Name()
+ return file.Name.Name
}
func parseDir(dirpath string) map[string]*ast.Package {
@@ -74,7 +74,7 @@ func main() {
flag.Parse()
var t0 int64
- pkgroot := os.Getenv("GOROOT") + "/src/pkg/"
+ pkgroot := runtime.GOROOT() + "/src/pkg/"
for pass := 0; pass < 2; pass++ {
// Once the heap is grown to full size, reset counters.
// This hides the start-up pauses, which are much smaller
@@ -115,7 +115,6 @@ var packages = []string{
"archive/tar",
"asn1",
"big",
- "bignum",
"bufio",
"bytes",
"cmath",
@@ -185,7 +184,6 @@ var packages = []string{
"mime",
"net",
"nntp",
- "once",
"os",
"os/signal",
"patch",
diff --git a/test/gc.go b/test/gc.go
index 864d05c39..3aab8fac9 100644
--- a/test/gc.go
+++ b/test/gc.go
@@ -11,7 +11,7 @@ import "runtime"
func mk2() {
b := new([10000]byte)
_ = b
- // println(b, "stored at", &b);
+ // println(b, "stored at", &b)
}
func mk1() { mk2() }
diff --git a/test/gc1.go b/test/gc1.go
index 055079aab..84034e7ce 100644
--- a/test/gc1.go
+++ b/test/gc1.go
@@ -8,7 +8,7 @@ package main
func main() {
for i := 0; i < 1e5; i++ {
- x := new([100]byte);
- _ = x;
+ x := new([100]byte)
+ _ = x
}
}
diff --git a/test/golden-arm.out b/test/golden-arm.out
deleted file mode 100644
index a51aea8e5..000000000
--- a/test/golden-arm.out
+++ /dev/null
@@ -1,110 +0,0 @@
-
-=========== ./cmp2.go
-panic: runtime error: comparing uncomparable type []int
-
-panic PC=xxx
-
-=========== ./cmp3.go
-panic: runtime error: comparing uncomparable type []int
-
-panic PC=xxx
-
-=========== ./cmp4.go
-panic: runtime error: hash of unhashable type []int
-
-panic PC=xxx
-
-=========== ./cmp5.go
-panic: runtime error: hash of unhashable type []int
-
-panic PC=xxx
-
-=========== ./helloworld.go
-hello, world
-
-=========== ./printbig.go
--9223372036854775808
-9223372036854775807
-
-=========== ./turing.go
-Hello World!
-
-=========== ken/intervar.go
- print 1 bio 2 file 3 -- abc
-
-=========== ken/label.go
-100
-
-=========== ken/rob1.go
-9876543210
-
-=========== ken/rob2.go
-(defn foo (add 12 34))
-
-=========== ken/simpprint.go
-hello world
-
-=========== ken/simpswitch.go
-0out01out12out2aout34out4fiveout56out6aout78out89out9
-
-=========== ken/string.go
-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz
-
-=========== chan/nonblock.go
-PASS
-
-=========== interface/fail.go
-panic: interface conversion: *main.S is not main.I: missing method Foo
-
-panic PC=xxx
-
-=========== interface/returntype.go
-panic: interface conversion: *main.S is not main.I2: missing method Name
-
-panic PC=xxx
-
-=========== fixedbugs/bug016.go
-fixedbugs/bug016.go:11: constant -3 overflows uint
-
-=========== fixedbugs/bug027.go
-hi
-0 44444
-1 3333
-2 222
-3 11
-4 0
-0 44444
-1 3333
-2 222
-3 11
-4 0
-
-=========== fixedbugs/bug067.go
-ok
-
-=========== fixedbugs/bug070.go
-outer loop top k 0
-inner loop top i 0
-do break
-broke
-
-=========== fixedbugs/bug081.go
-fixedbugs/bug081.go:9: typechecking loop
-
-=========== fixedbugs/bug093.go
-M
-
-=========== fixedbugs/bug113.go
-panic: interface conversion: interface is int, not int32
-
-panic PC=xxx
-
-=========== fixedbugs/bug148.go
-2 3
-panic: interface conversion: interface is main.T, not main.T
-
-panic PC=xxx
-
-=========== bugs/bug260.go
-FAIL
-BUG: bug260 failed
diff --git a/test/golden.out b/test/golden.out
index 82e85340a..e587912a4 100644
--- a/test/golden.out
+++ b/test/golden.out
@@ -173,17 +173,3 @@ panic: interface conversion: interface is main.T, not main.T
panic PC=xxx
== bugs/
-
-=========== bugs/bug260.go
-FAIL
-BUG: bug260 failed
-
-=========== bugs/bug274.go
-BUG: errchk: command succeeded unexpectedly
-
-=========== bugs/bug286.go
-test2 called g
-panic: wrong method called
-
-panic PC=xxx
-BUG: bug286 failed
diff --git a/test/hashmap.go b/test/hashmap.go
index 62943a713..0a4d7ab61 100755
--- a/test/hashmap.go
+++ b/test/hashmap.go
@@ -11,7 +11,7 @@ package main
func ASSERT(p bool) {
if !p {
- // panic 0;
+ // panic 0
}
}
@@ -20,8 +20,8 @@ func ASSERT(p bool) {
// Implementation of the HashMap
type KeyType interface {
- Hash() uint32;
- Match(other *KeyType) bool
+ Hash() uint32
+ Match(other KeyType) bool
}
@@ -31,31 +31,30 @@ type ValueType interface {
type Entry struct {
- key *KeyType;
- value *ValueType;
+ key KeyType
+ value ValueType
}
-// Using the Array type below doesn't seem to work
-//type Array array [1024] Entry;
+type Array [1024]Entry
type HashMap struct {
- map_ *[1024] Entry;
- log2_capacity_ uint32;
- occupancy_ uint32;
+ map_ *Array
+ log2_capacity_ uint32
+ occupancy_ uint32
}
func (m *HashMap) capacity() uint32 {
- return 1 << m.log2_capacity_;
+ return 1 << m.log2_capacity_
}
func (m *HashMap) Clear() {
// Mark all entries as empty.
- var i uint32 = m.capacity() - 1;
+ var i uint32 = m.capacity() - 1
for i > 0 {
- m.map_[i].key = nil;
+ m.map_[i].key = nil
i = i - 1
}
m.occupancy_ = 0
@@ -63,72 +62,72 @@ func (m *HashMap) Clear() {
func (m *HashMap) Initialize (initial_log2_capacity uint32) {
- m.log2_capacity_ = initial_log2_capacity;
- m.map_ = new([1024] Entry);
- m.Clear();
+ m.log2_capacity_ = initial_log2_capacity
+ m.map_ = new(Array)
+ m.Clear()
}
-func (m *HashMap) Probe (key *KeyType) *Entry {
- ASSERT(key != nil);
+func (m *HashMap) Probe (key KeyType) *Entry {
+ ASSERT(key != nil)
- var i uint32 = key.Hash() % m.capacity();
- ASSERT(0 <= i && i < m.capacity());
+ var i uint32 = key.Hash() % m.capacity()
+ ASSERT(0 <= i && i < m.capacity())
- ASSERT(m.occupancy_ < m.capacity()); // guarantees loop termination
+ ASSERT(m.occupancy_ < m.capacity()) // guarantees loop termination
for m.map_[i].key != nil && !m.map_[i].key.Match(key) {
- i++;
+ i++
if i >= m.capacity() {
- i = 0;
+ i = 0
}
}
- return &m.map_[i];
+ return &m.map_[i]
}
-func (m *HashMap) Lookup (key *KeyType, insert bool) *Entry {
+func (m *HashMap) Lookup (key KeyType, insert bool) *Entry {
// Find a matching entry.
- var p *Entry = m.Probe(key);
+ var p *Entry = m.Probe(key)
if p.key != nil {
- return p;
+ return p
}
// No entry found; insert one if necessary.
if insert {
- p.key = key;
- p.value = nil;
- m.occupancy_++;
+ p.key = key
+ p.value = nil
+ m.occupancy_++
// Grow the map if we reached >= 80% occupancy.
if m.occupancy_ + m.occupancy_/4 >= m.capacity() {
- m.Resize();
- p = m.Probe(key);
+ m.Resize()
+ p = m.Probe(key)
}
- return p;
+ return p
}
// No entry found and none inserted.
- return nil;
+ return nil
}
func (m *HashMap) Resize() {
- var hmap *[1024] Entry = m.map_;
- var n uint32 = m.occupancy_;
+ var hmap *Array = m.map_
+ var n uint32 = m.occupancy_
// Allocate a new map of twice the current size.
- m.Initialize(m.log2_capacity_ << 1);
+ m.Initialize(m.log2_capacity_ << 1)
// Rehash all current entries.
- var i uint32 = 0;
+ var i uint32 = 0
for n > 0 {
if hmap[i].key != nil {
- m.Lookup(hmap[i].key, true).value = hmap[i].value;
- n = n - 1;
+ m.Lookup(hmap[i].key, true).value = hmap[i].value
+ n = n - 1
}
- i++;
+ i++
}
}
@@ -137,46 +136,46 @@ func (m *HashMap) Resize() {
// Test code
type Number struct {
- x uint32;
+ x uint32
}
func (n *Number) Hash() uint32 {
- return n.x * 23;
+ return n.x * 23
}
-func (n *Number) Match(other *KeyType) bool {
- // var y *Number = other;
- // return n.x == y.x;
- return false;
+func (n *Number) Match(other KeyType) bool {
+ // var y *Number = other
+ // return n.x == y.x
+ return false
}
func MakeNumber (x uint32) *Number {
- var n *Number = new(Number);
- n.x = x;
- return n;
+ var n *Number = new(Number)
+ n.x = x
+ return n
}
func main() {
- //f unc (n int) int { return n + 1; }(1);
+ // func (n int) int { return n + 1; }(1)
- //print "HashMap - gri 2/8/2008\n";
+ //print "HashMap - gri 2/8/2008\n"
- var hmap *HashMap = new(HashMap);
- hmap.Initialize(0);
+ var hmap *HashMap = new(HashMap)
+ hmap.Initialize(0)
- var x1 *Number = MakeNumber(1001);
- var x2 *Number = MakeNumber(2002);
- var x3 *Number = MakeNumber(3003);
- _, _, _ = x1, x2, x3;
+ var x1 *Number = MakeNumber(1001)
+ var x2 *Number = MakeNumber(2002)
+ var x3 *Number = MakeNumber(3003)
+ _, _, _ = x1, x2, x3
// this doesn't work I think...
- //hmap.Lookup(x1, true);
- //hmap.Lookup(x2, true);
- //hmap.Lookup(x3, true);
+ //hmap.Lookup(x1, true)
+ //hmap.Lookup(x2, true)
+ //hmap.Lookup(x3, true)
- //print "done\n";
+ //print "done\n"
}
diff --git a/test/helloworld.go b/test/helloworld.go
index 7234be35c..e55a74bbd 100644
--- a/test/helloworld.go
+++ b/test/helloworld.go
@@ -7,5 +7,5 @@
package main
func main() {
- print("hello, world\n");
+ print("hello, world\n")
}
diff --git a/test/if.go b/test/if.go
index c7f14c42a..db1fe8b79 100644
--- a/test/if.go
+++ b/test/if.go
@@ -8,92 +8,92 @@ package main
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
- print("assertion fail", msg, "\n");
- panic(1);
+ print("assertion fail", msg, "\n")
+ panic(1)
}
}
func main() {
- i5 := 5;
- i7 := 7;
+ i5 := 5
+ i7 := 7
- var count int;
+ var count int
- count = 0;
+ count = 0
if true {
- count = count + 1;
+ count = count + 1
}
- assertequal(count, 1, "if true");
+ assertequal(count, 1, "if true")
- count = 0;
+ count = 0
if false {
- count = count + 1;
+ count = count + 1
}
- assertequal(count, 0, "if false");
+ assertequal(count, 0, "if false")
- count = 0;
+ count = 0
if one := 1; true {
- count = count + one;
+ count = count + one
}
- assertequal(count, 1, "if true one");
+ assertequal(count, 1, "if true one")
- count = 0;
+ count = 0
if one := 1; false {
- count = count + 1;
- _ = one;
+ count = count + 1
+ _ = one
}
- assertequal(count, 0, "if false one");
+ assertequal(count, 0, "if false one")
- count = 0;
+ count = 0
if {
- count = count + 1;
+ count = count + 1
}
- assertequal(count, 1, "if empty");
+ assertequal(count, 1, "if empty")
- count = 0;
+ count = 0
if one := 1; true {
- count = count + one;
+ count = count + one
}
- assertequal(count, 1, "if empty one");
+ assertequal(count, 1, "if empty one")
- count = 0;
+ count = 0
if i5 < i7 {
- count = count + 1;
+ count = count + 1
}
- assertequal(count, 1, "if cond");
+ assertequal(count, 1, "if cond")
- count = 0;
+ count = 0
if true {
- count = count + 1;
+ count = count + 1
} else
- count = count - 1;
- assertequal(count, 1, "if else true");
+ count = count - 1
+ assertequal(count, 1, "if else true")
- count = 0;
+ count = 0
if false {
- count = count + 1;
+ count = count + 1
} else
- count = count - 1;
- assertequal(count, -1, "if else false");
+ count = count - 1
+ assertequal(count, -1, "if else false")
- count = 0;
+ count = 0
if t:=1; false {
- count = count + 1;
- _ = t;
- t := 7;
- _ = t;
+ count = count + 1
+ _ = t
+ t := 7
+ _ = t
} else
- count = count - t;
- assertequal(count, -1, "if else false var");
+ count = count - t
+ assertequal(count, -1, "if else false var")
- count = 0;
- t := 1;
+ count = 0
+ t := 1
if false {
- count = count + 1;
- t := 7;
- _ = t;
+ count = count + 1
+ t := 7
+ _ = t
} else
- count = count - t;
- _ = t;
- assertequal(count, -1, "if else false var outside");
+ count = count - t
+ _ = t
+ assertequal(count, -1, "if else false var outside")
}
diff --git a/test/if1.go b/test/if1.go
index 3f3ef1597..061c36411 100644
--- a/test/if1.go
+++ b/test/if1.go
@@ -9,12 +9,12 @@ package main
import "os"
func main() {
- count := 7;
+ count := 7
if one := 1; {
count = count + one
}
if count != 8 {
- print(count, " should be 8\n");
+ print(count, " should be 8\n")
os.Exit(1)
}
}
diff --git a/test/import.go b/test/import.go
index 9bed8213c..96330340d 100644
--- a/test/import.go
+++ b/test/import.go
@@ -16,10 +16,10 @@ import . "os"
func f(e os.Error)
func main() {
- var _e_ _os_.Error;
- var dot Error;
+ var _e_ _os_.Error
+ var dot Error
- f(_e_);
- f(dot);
+ f(_e_)
+ f(dot)
}
diff --git a/test/import1.go b/test/import1.go
index 351462a26..8bb2a94a2 100644
--- a/test/import1.go
+++ b/test/import1.go
@@ -12,6 +12,6 @@ import "bufio" // GCCGO_ERROR "previous|not used"
import bufio "os" // ERROR "redeclared|redefinition|incompatible"
import (
- "fmt"; // GCCGO_ERROR "previous|not used"
- fmt "math"; // ERROR "redeclared|redefinition|incompatible"
+ "fmt" // GCCGO_ERROR "previous|not used"
+ fmt "math" // ERROR "redeclared|redefinition|incompatible"
)
diff --git a/test/index.go b/test/index.go
new file mode 100644
index 000000000..38aa33dd3
--- /dev/null
+++ b/test/index.go
@@ -0,0 +1,224 @@
+// $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 code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Generate test of index and slice bounds checks.
+
+package main
+
+import (
+ "bufio"
+ "flag"
+ "fmt"
+ "os"
+)
+
+const prolog = `
+
+package main
+
+import (
+ "runtime"
+)
+
+type quad struct { x, y, z, w int }
+
+const (
+ cj = 11
+ ci int = 12
+ ci32 int32 = 13
+ ci64 int64 = 14
+ ci64big int64 = 1<<31
+ ci64bigger int64 = 1<<32
+ chuge = 1<<100
+
+ cnj = -2
+ cni int = -3
+ cni32 int32 = -4
+ cni64 int64 = -5
+ cni64big int64 = -1<<31
+ cni64bigger int64 = -1<<32
+ cnhuge = -1<<100
+)
+
+var j int = 20
+var i int = 21
+var i32 int32 = 22
+var i64 int64 = 23
+var i64big int64 = 1<<31
+var i64bigger int64 = 1<<32
+var huge uint64 = 1<<64 - 1
+
+var nj int = -10
+var ni int = -11
+var ni32 int32 = -12
+var ni64 int64 = -13
+var ni64big int64 = -1<<31
+var ni64bigger int64 = -1<<32
+var nhuge int64 = -1<<63
+
+var si []int = make([]int, 10)
+var ai [10]int
+var pai *[10]int = &ai
+
+var sq []quad = make([]quad, 10)
+var aq [10]quad
+var paq *[10]quad = &aq
+
+type T struct {
+ si []int
+ ai [10]int
+ pai *[10]int
+ sq []quad
+ aq [10]quad
+ paq *[10]quad
+}
+
+var t = T{si, ai, pai, sq, aq, paq}
+
+var pt = &T{si, ai, pai, sq, aq, paq}
+
+// test that f panics
+func test(f func(), s string) {
+ defer func() {
+ if err := recover(); err == nil {
+ _, file, line, _ := runtime.Caller(2)
+ bug()
+ print(file, ":", line, ": ", s, " did not panic\n")
+ }
+ }()
+ f()
+}
+
+var X interface{}
+func use(y interface{}) {
+ X = y
+}
+
+var didBug = false
+
+func bug() {
+ if !didBug {
+ didBug = true
+ println("BUG")
+ }
+}
+
+func main() {
+`
+
+// Passes:
+// 0 - dynamic checks
+// 1 - static checks of invalid constants (cannot assign to types)
+// 2 - static checks of array bounds
+var pass = flag.Int("pass", 0, "which test (0,1,2)")
+
+func testExpr(b *bufio.Writer, expr string) {
+ if *pass == 0 {
+ fmt.Fprintf(b, "\ttest(func(){use(%s)}, %q)\n", expr, expr)
+ } else {
+ fmt.Fprintf(b, "\tuse(%s) // ERROR \"index|overflow\"\n", expr)
+ }
+}
+
+func main() {
+ b := bufio.NewWriter(os.Stdout)
+
+ flag.Parse()
+
+ if *pass == 0 {
+ fmt.Fprint(b, "// $G $D/$F.go && $L $F.$A && ./$A.out\n\n")
+ } else {
+ fmt.Fprint(b, "// errchk $G -e $D/$F.go\n\n")
+ }
+ fmt.Fprint(b, prolog)
+
+ var choices = [][]string{
+ // Direct value, fetch from struct, fetch from struct pointer.
+ // The last two cases get us to oindex_const_sudo in gsubr.c.
+ []string{"", "t.", "pt."},
+
+ // Array, pointer to array, slice.
+ []string{"a", "pa", "s"},
+
+ // Element is int, element is quad (struct).
+ // This controls whether we end up in gsubr.c (i) or cgen.c (q).
+ []string{"i", "q"},
+
+ // Variable or constant.
+ []string{"", "c"},
+
+ // Positive or negative.
+ []string{"", "n"},
+
+ // Size of index.
+ []string{"j", "i", "i32", "i64", "i64big", "i64bigger", "huge"},
+ }
+
+ forall(choices, func(x []string) {
+ p, a, e, c, n, i := x[0], x[1], x[2], x[3], x[4], x[5]
+
+ // Pass: dynamic=0, static=1, 2.
+ // Which cases should be caught statically?
+ // Only constants, obviously.
+ // Beyond that, must be one of these:
+ // indexing into array or pointer to array
+ // negative constant
+ // large constant
+ thisPass := 0
+ if c == "c" && (a == "a" || a == "pa" || n == "n" || i == "i64big" || i == "i64bigger" || i == "huge") {
+ if i == "huge" {
+ // Due to a detail of 6g's internals,
+ // the huge constant errors happen in an
+ // earlier pass than the others and inhibits
+ // the next pass from running.
+ // So run it as a separate check.
+ thisPass = 1
+ } else {
+ thisPass = 2
+ }
+ }
+
+ // Only print the test case if it is appropriate for this pass.
+ if thisPass == *pass {
+ pae := p+a+e
+ cni := c+n+i
+
+ // Index operation
+ testExpr(b, pae + "[" + cni + "]")
+
+ // Slice operation.
+ // Low index 0 is a special case in ggen.c
+ // so test both 0 and 1.
+ testExpr(b, pae + "[0:" + cni + "]")
+ testExpr(b, pae + "[1:" + cni + "]")
+ testExpr(b, pae + "[" + cni + ":]")
+ testExpr(b, pae + "[" + cni + ":" + cni + "]")
+ }
+ })
+
+ fmt.Fprintln(b, "}")
+ b.Flush()
+}
+
+func forall(choices [][]string, f func([]string)) {
+ x := make([]string, len(choices))
+
+ var recurse func(d int)
+ recurse = func(d int) {
+ if d >= len(choices) {
+ f(x)
+ return
+ }
+ for _, x[d] = range choices[d] {
+ recurse(d+1)
+ }
+ }
+ recurse(0)
+}
diff --git a/test/indirect1.go b/test/indirect1.go
index 7cd476a01..0fd5c19d4 100644
--- a/test/indirect1.go
+++ b/test/indirect1.go
@@ -64,5 +64,5 @@ func f() {
cap(b1)+ // ERROR "illegal|invalid|must be"
cap(b2)+ // ERROR "illegal|invalid|must be"
cap(b3)+
- cap(b4); // ERROR "illegal|invalid|must be"
+ cap(b4) // ERROR "illegal|invalid|must be"
}
diff --git a/test/initialize.go b/test/initialize.go
index 807bf5bda..6dd7d67dc 100644
--- a/test/initialize.go
+++ b/test/initialize.go
@@ -10,11 +10,11 @@ import "fmt"
import "reflect"
type S struct {
- A, B, C, X, Y, Z int;
+ A, B, C, X, Y, Z int
}
type T struct {
- S;
+ S
}
var a1 = S { 0, 0, 0, 1, 2, 3 }
@@ -49,14 +49,14 @@ var same = []Same {
}
func main() {
- ok := true;
+ ok := true
for _, s := range same {
if !reflect.DeepEqual(s.a, s.b) {
- ok = false;
- fmt.Printf("not same: %v and %v\n", s.a, s.b);
+ ok = false
+ fmt.Printf("not same: %v and %v\n", s.a, s.b)
}
}
if !ok {
- fmt.Println("BUG: test/initialize");
+ fmt.Println("BUG: test/initialize")
}
}
diff --git a/test/initializerr.go b/test/initializerr.go
index b0366ddde..37f8a602d 100644
--- a/test/initializerr.go
+++ b/test/initializerr.go
@@ -7,17 +7,17 @@
package main
type S struct {
- A, B, C, X, Y, Z int;
+ A, B, C, X, Y, Z int
}
type T struct {
- S;
+ S
}
var x = 1
-var a1 = S { 0, X: 1 }; // ERROR "mixture|undefined"
-var a2 = S { Y: 3, Z: 2, Y: 3 }; // ERROR "duplicate"
-var a3 = T { 1, 2, 3, 4, 5, 6 }; // ERROR "convert|too many"
+var a1 = S { 0, X: 1 } // ERROR "mixture|undefined"
+var a2 = S { Y: 3, Z: 2, Y: 3 } // ERROR "duplicate"
+var a3 = T { 1, 2, 3, 4, 5, 6 } // ERROR "convert|too many"
var a4 = [5]byte{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } // ERROR "index|too many"
var a5 = []byte { x: 2 } // ERROR "index"
diff --git a/test/initsyscall.go b/test/initsyscall.go
index 139bb0acb..b5e5812b6 100644
--- a/test/initsyscall.go
+++ b/test/initsyscall.go
@@ -18,8 +18,8 @@ func f() {
}
func init() {
- go f();
- time.Nanoseconds();
+ go f()
+ time.Nanoseconds()
}
func main() {
diff --git a/test/int_lit.go b/test/int_lit.go
index 1cb42f5d1..2644e17b5 100644
--- a/test/int_lit.go
+++ b/test/int_lit.go
@@ -16,9 +16,9 @@ func main() {
0x0 +
0x123 +
0X0 +
- 0X123;
+ 0X123
if s != 788 {
- print("s is ", s, "; should be 788\n");
- os.Exit(1);
+ print("s is ", s, "; should be 788\n")
+ os.Exit(1)
}
}
diff --git a/test/interface/bigdata.go b/test/interface/bigdata.go
index 674ea1276..44f6ab127 100644
--- a/test/interface/bigdata.go
+++ b/test/interface/bigdata.go
@@ -23,24 +23,24 @@ func (z *IntPtr) M() int64 { return int64(*z) }
var bad bool
func test(name string, i I) {
- m := i.M();
+ m := i.M()
if m != 12345 {
- println(name, m);
- bad = true;
+ println(name, m)
+ bad = true
}
}
func ptrs() {
- var bigptr BigPtr = BigPtr{ 10000, 2000, 300, 45 };
- var smallptr SmallPtr = SmallPtr{ 12345 };
- var intptr IntPtr = 12345;
-
-// test("bigptr", bigptr);
- test("&bigptr", &bigptr);
-// test("smallptr", smallptr);
- test("&smallptr", &smallptr);
-// test("intptr", intptr);
- test("&intptr", &intptr);
+ var bigptr BigPtr = BigPtr{ 10000, 2000, 300, 45 }
+ var smallptr SmallPtr = SmallPtr{ 12345 }
+ var intptr IntPtr = 12345
+
+// test("bigptr", bigptr)
+ test("&bigptr", &bigptr)
+// test("smallptr", smallptr)
+ test("&smallptr", &smallptr)
+// test("intptr", intptr)
+ test("&intptr", &intptr)
}
type Big struct { a, b, c, d int64 }
@@ -53,23 +53,23 @@ type Int int32
func (z Int) M() int64 { return int64(z) }
func nonptrs() {
- var big Big = Big{ 10000, 2000, 300, 45 };
- var small Small = Small{ 12345 };
- var int Int = 12345;
-
- test("big", big);
- test("&big", &big);
- test("small", small);
- test("&small", &small);
- test("int", int);
- test("&int", &int);
+ var big Big = Big{ 10000, 2000, 300, 45 }
+ var small Small = Small{ 12345 }
+ var int Int = 12345
+
+ test("big", big)
+ test("&big", &big)
+ test("small", small)
+ test("&small", &small)
+ test("int", int)
+ test("&int", &int)
}
func main() {
- ptrs();
- nonptrs();
+ ptrs()
+ nonptrs()
if bad {
- println("BUG: interface4");
+ println("BUG: interface4")
}
}
diff --git a/test/interface/convert1.go b/test/interface/convert1.go
index 0eff6a95d..658b1a92f 100644
--- a/test/interface/convert1.go
+++ b/test/interface/convert1.go
@@ -9,17 +9,17 @@
package main
-type R interface { R(); }
-type RW interface { R(); W(); }
+type R interface { R() }
+type RW interface { R(); W() }
var e interface {}
-var r R;
-var rw RW;
+var r R
+var rw RW
func main() {
- r = r;
- r = rw;
- e = r;
- e = rw;
- rw = rw;
+ r = r
+ r = rw
+ e = r
+ e = rw
+ rw = rw
}
diff --git a/test/interface/convert2.go b/test/interface/convert2.go
index 0eff6a95d..658b1a92f 100644
--- a/test/interface/convert2.go
+++ b/test/interface/convert2.go
@@ -9,17 +9,17 @@
package main
-type R interface { R(); }
-type RW interface { R(); W(); }
+type R interface { R() }
+type RW interface { R(); W() }
var e interface {}
-var r R;
-var rw RW;
+var r R
+var rw RW
func main() {
- r = r;
- r = rw;
- e = r;
- e = rw;
- rw = rw;
+ r = r
+ r = rw
+ e = r
+ e = rw
+ rw = rw
}
diff --git a/test/interface/embed.go b/test/interface/embed.go
index 936ea49b7..2fddee190 100644
--- a/test/interface/embed.go
+++ b/test/interface/embed.go
@@ -4,7 +4,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// Check methods derived from embedded interface and *interface values.
+// Check methods derived from embedded interface values.
package main
@@ -19,64 +19,43 @@ func (t T) M() int64 { return int64(t) }
var t = T(Value)
var pt = &t
var ti Inter = t
-var pti = &ti
type S struct { Inter }
var s = S{ ti }
var ps = &s
-type SP struct { *Inter }
-var sp = SP{ &ti }
-var psp = &sp
-
var i Inter
-var pi = &i
var ok = true
func check(s string, v int64) {
if v != Value {
- println(s, v);
- ok = false;
+ println(s, v)
+ ok = false
}
}
func main() {
- check("t.M()", t.M());
- check("pt.M()", pt.M());
- check("ti.M()", ti.M());
- check("pti.M()", pti.M());
- check("s.M()", s.M());
- check("ps.M()", ps.M());
- check("sp.M()", sp.M());
- check("psp.M()", psp.M());
-
- i = t;
- check("i = t; i.M()", i.M());
- check("i = t; pi.M()", pi.M());
-
- i = pt;
- check("i = pt; i.M()", i.M());
- check("i = pt; pi.M()", pi.M());
-
- i = s;
- check("i = s; i.M()", i.M());
- check("i = s; pi.M()", pi.M());
-
- i = ps;
- check("i = ps; i.M()", i.M());
- check("i = ps; pi.M()", pi.M());
-
- i = sp;
- check("i = sp; i.M()", i.M());
- check("i = sp; pi.M()", pi.M());
-
- i = psp;
- check("i = psp; i.M()", i.M());
- check("i = psp; pi.M()", pi.M());
+ check("t.M()", t.M())
+ check("pt.M()", pt.M())
+ check("ti.M()", ti.M())
+ check("s.M()", s.M())
+ check("ps.M()", ps.M())
+
+ i = t
+ check("i = t; i.M()", i.M())
+
+ i = pt
+ check("i = pt; i.M()", i.M())
+
+ i = s
+ check("i = s; i.M()", i.M())
+
+ i = ps
+ check("i = ps; i.M()", i.M())
if !ok {
- println("BUG: interface10");
+ println("BUG: interface10")
os.Exit(1)
}
}
diff --git a/test/interface/embed0.go b/test/interface/embed0.go
index fd16e2733..bbd81e760 100644
--- a/test/interface/embed0.go
+++ b/test/interface/embed0.go
@@ -12,18 +12,18 @@ type T int
func (t T) m() {}
type I interface { m() }
-type J interface { I; }
+type J interface { I }
func main() {
- var i I;
- var j J;
- var t T;
- i = t;
- j = t;
- _ = i;
- _ = j;
- i = j;
- _ = i;
- j = i;
- _ = j;
+ var i I
+ var j J
+ var t T
+ i = t
+ j = t
+ _ = i
+ _ = j
+ i = j
+ _ = i
+ j = i
+ _ = j
}
diff --git a/test/interface/embed1.go b/test/interface/embed1.go
index 6e15031ea..24e50471f 100644
--- a/test/interface/embed1.go
+++ b/test/interface/embed1.go
@@ -14,32 +14,32 @@ type T int
func (t T) m() {}
type I interface { m() }
-type J interface { I; }
+type J interface { I }
-type PI interface { p.I; }
-type PJ interface { p.J; }
+type PI interface { p.I }
+type PJ interface { p.J }
func main() {
- var i I;
- var j J;
- var t T;
- i = t;
- j = t;
- _ = i;
- _ = j;
- i = j;
- _ = i;
- j = i;
- _ = j;
- var pi PI;
- var pj PJ;
- var pt p.T;
- pi = pt;
- pj = pt;
- _ = pi;
- _ = pj;
- pi = pj;
- _ = pi;
- pj = pi;
- _ = pj;
+ var i I
+ var j J
+ var t T
+ i = t
+ j = t
+ _ = i
+ _ = j
+ i = j
+ _ = i
+ j = i
+ _ = j
+ var pi PI
+ var pj PJ
+ var pt p.T
+ pi = pt
+ pj = pt
+ _ = pi
+ _ = pj
+ pi = pj
+ _ = pi
+ pj = pi
+ _ = pj
}
diff --git a/test/interface/embed2.go b/test/interface/embed2.go
new file mode 100644
index 000000000..c18a1fece
--- /dev/null
+++ b/test/interface/embed2.go
@@ -0,0 +1,70 @@
+// errchk $G -e $D/$F.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 LICENSE file.
+
+// Check methods derived from embedded interface and *interface values.
+
+package main
+
+import "os"
+
+const Value = 1e12
+
+type Inter interface { M() int64 }
+
+type T int64
+func (t T) M() int64 { return int64(t) }
+var t = T(Value)
+var pt = &t
+var ti Inter = t
+var pti = &ti
+
+type S struct { Inter }
+var s = S{ ti }
+var ps = &s
+
+type SP struct { *Inter } // ERROR "interface"
+
+var i Inter
+var pi = &i
+
+var ok = true
+
+func check(s string, v int64) {
+ if v != Value {
+ println(s, v)
+ ok = false
+ }
+}
+
+func main() {
+ check("t.M()", t.M())
+ check("pt.M()", pt.M())
+ check("ti.M()", ti.M())
+ check("pti.M()", pti.M()) // ERROR "method"
+ check("s.M()", s.M())
+ check("ps.M()", ps.M())
+
+ i = t
+ check("i = t; i.M()", i.M())
+ check("i = t; pi.M()", pi.M()) // ERROR "method"
+
+ i = pt
+ check("i = pt; i.M()", i.M())
+ check("i = pt; pi.M()", pi.M()) // ERROR "method"
+
+ i = s
+ check("i = s; i.M()", i.M())
+ check("i = s; pi.M()", pi.M()) // ERROR "method"
+
+ i = ps
+ check("i = ps; i.M()", i.M())
+ check("i = ps; pi.M()", pi.M()) // ERROR "method"
+
+ if !ok {
+ println("BUG: interface10")
+ os.Exit(1)
+ }
+}
diff --git a/test/interface/explicit.go b/test/interface/explicit.go
index 120135cb6..b952f8fc8 100644
--- a/test/interface/explicit.go
+++ b/test/interface/explicit.go
@@ -42,10 +42,10 @@ func main() {
t = i // ERROR "incompatible|need type assertion"
i = i2 // ok
- i2 = i // ERROR "missing N method"
+ i2 = i // ERROR "incompatible|missing N method"
i = I(i2) // ok
- i2 = I2(i) // ERROR "missing N method"
+ i2 = I2(i) // ERROR "invalid|missing N method"
e = E(t) // ok
t = T(e) // ERROR "need explicit|need type assertion|incompatible"
@@ -64,8 +64,8 @@ var _ = m.(Int) // ERROR "impossible type assertion"
var ii int
var jj Int
-var m1 M = ii // ERROR "missing"
-var m2 M = jj // ERROR "wrong type for M method"
+var m1 M = ii // ERROR "incompatible|missing"
+var m2 M = jj // ERROR "incompatible|wrong type for M method"
-var m3 = M(ii) // ERROR "missing"
-var m4 = M(jj) // ERROR "wrong type for M method"
+var m3 = M(ii) // ERROR "invalid|missing"
+var m4 = M(jj) // ERROR "invalid|wrong type for M method"
diff --git a/test/interface/fail.go b/test/interface/fail.go
index 07bd865c8..3e741d3f9 100644
--- a/test/interface/fail.go
+++ b/test/interface/fail.go
@@ -13,12 +13,12 @@ type I interface {
}
func main() {
- var s *S;
- var i I;
- var e interface {};
- e = s;
- i = e.(I);
- _ = i;
+ var s *S
+ var i I
+ var e interface {}
+ e = s
+ i = e.(I)
+ _ = i
}
// hide S down here to avoid static warning
diff --git a/test/interface/fake.go b/test/interface/fake.go
index 687b3ff0c..5cf3be052 100644
--- a/test/interface/fake.go
+++ b/test/interface/fake.go
@@ -12,69 +12,69 @@ package main
import "reflect"
type T struct {
- f float32;
- g float32;
+ f float32
+ g float32
- s string;
- t string;
+ s string
+ t string
- u uint32;
- v uint32;
+ u uint32
+ v uint32
- w uint32;
- x uint32;
+ w uint32
+ x uint32
- y uint32;
- z uint32;
+ y uint32
+ z uint32
}
func add(s, t string) string {
- return s + t;
+ return s + t
}
func assert(b bool) {
if !b {
- panic("assert");
+ panic("assert")
}
}
func main() {
- var x T;
- x.f = 1.0;
- x.g = x.f;
- x.s = add("abc", "def");
- x.t = add("abc", "def");
- x.u = 1;
- x.v = 2;
- x.w = 1<<28;
- x.x = 2<<28;
- x.y = 0x12345678;
- x.z = x.y;
+ var x T
+ x.f = 1.0
+ x.g = x.f
+ x.s = add("abc", "def")
+ x.t = add("abc", "def")
+ x.u = 1
+ x.v = 2
+ x.w = 1<<28
+ x.x = 2<<28
+ x.y = 0x12345678
+ x.z = x.y
// check mem and string
- v := reflect.NewValue(x);
- i := v.(*reflect.StructValue).Field(0);
- j := v.(*reflect.StructValue).Field(1);
- assert(i.Interface() == j.Interface());
+ v := reflect.NewValue(x)
+ i := v.(*reflect.StructValue).Field(0)
+ j := v.(*reflect.StructValue).Field(1)
+ assert(i.Interface() == j.Interface())
- s := v.(*reflect.StructValue).Field(2);
- t := v.(*reflect.StructValue).Field(3);
- assert(s.Interface() == t.Interface());
+ s := v.(*reflect.StructValue).Field(2)
+ t := v.(*reflect.StructValue).Field(3)
+ assert(s.Interface() == t.Interface())
// make sure different values are different.
// make sure whole word is being compared,
// not just a single byte.
- i = v.(*reflect.StructValue).Field(4);
- j = v.(*reflect.StructValue).Field(5);
- assert(i.Interface() != j.Interface());
+ i = v.(*reflect.StructValue).Field(4)
+ j = v.(*reflect.StructValue).Field(5)
+ assert(i.Interface() != j.Interface())
- i = v.(*reflect.StructValue).Field(6);
- j = v.(*reflect.StructValue).Field(7);
- assert(i.Interface() != j.Interface());
+ i = v.(*reflect.StructValue).Field(6)
+ j = v.(*reflect.StructValue).Field(7)
+ assert(i.Interface() != j.Interface())
- i = v.(*reflect.StructValue).Field(8);
- j = v.(*reflect.StructValue).Field(9);
- assert(i.Interface() == j.Interface());
+ i = v.(*reflect.StructValue).Field(8)
+ j = v.(*reflect.StructValue).Field(9)
+ assert(i.Interface() == j.Interface())
}
/*
diff --git a/test/interface/receiver.go b/test/interface/receiver.go
index f74cecb2c..f53daf8da 100644
--- a/test/interface/receiver.go
+++ b/test/interface/receiver.go
@@ -64,7 +64,7 @@ func main() {
v = &t
v.V()
- // p = t; // ERROR
+ // p = t // ERROR
var i interface{} = t
if _, ok := i.(P); ok {
println("dynamic i.(P) succeeded incorrectly")
@@ -87,7 +87,7 @@ func main() {
v = &s
v.V()
- // p = s; // ERROR
+ // p = s // ERROR
var j interface{} = s
if _, ok := j.(P); ok {
println("dynamic j.(P) succeeded incorrectly")
diff --git a/test/interface/returntype.go b/test/interface/returntype.go
index 93298bce7..c526b3b0e 100644
--- a/test/interface/returntype.go
+++ b/test/interface/returntype.go
@@ -18,8 +18,8 @@ type I1 interface { Name() int8 }
type I2 interface { Name() int64 }
func main() {
- var i1 I1;
- var s *S;
- i1 = s;
+ var i1 I1
+ var s *S
+ i1 = s
print(i1.(I2).Name())
}
diff --git a/test/interface/struct.go b/test/interface/struct.go
index 1c7028e06..40b7f4f91 100644
--- a/test/interface/struct.go
+++ b/test/interface/struct.go
@@ -14,39 +14,39 @@ var fail int
func check(b bool, msg string) {
if (!b) {
- println("failure in", msg);
- fail++;
+ println("failure in", msg)
+ fail++
}
}
-type I1 interface { Get() int; Put(int); }
+type I1 interface { Get() int; Put(int) }
type S1 struct { i int }
func (p S1) Get() int { return p.i }
func (p S1) Put(i int) { p.i = i }
func f1() {
- s := S1{1};
- var i I1 = s;
- i.Put(2);
- check(i.Get() == 1, "f1 i");
- check(s.i == 1, "f1 s");
+ s := S1{1}
+ var i I1 = s
+ i.Put(2)
+ check(i.Get() == 1, "f1 i")
+ check(s.i == 1, "f1 s")
}
func f2() {
- s := S1{1};
- var i I1 = &s;
- i.Put(2);
- check(i.Get() == 1, "f2 i");
- check(s.i == 1, "f2 s");
+ s := S1{1}
+ var i I1 = &s
+ i.Put(2)
+ check(i.Get() == 1, "f2 i")
+ check(s.i == 1, "f2 s")
}
func f3() {
- s := &S1{1};
- var i I1 = s;
- i.Put(2);
- check(i.Get() == 1, "f3 i");
- check(s.i == 1, "f3 s");
+ s := &S1{1}
+ var i I1 = s
+ i.Put(2)
+ check(i.Get() == 1, "f3 i")
+ check(s.i == 1, "f3 s")
}
type S2 struct { i int }
@@ -55,57 +55,57 @@ func (p *S2) Put(i int) { p.i = i }
// Disallowed by restriction of values going to pointer receivers
// func f4() {
-// s := S2{1};
-// var i I1 = s;
-// i.Put(2);
-// check(i.Get() == 2, "f4 i");
-// check(s.i == 1, "f4 s");
+// s := S2{1}
+// var i I1 = s
+// i.Put(2)
+// check(i.Get() == 2, "f4 i")
+// check(s.i == 1, "f4 s")
// }
func f5() {
- s := S2{1};
- var i I1 = &s;
- i.Put(2);
- check(i.Get() == 2, "f5 i");
- check(s.i == 2, "f5 s");
+ s := S2{1}
+ var i I1 = &s
+ i.Put(2)
+ check(i.Get() == 2, "f5 i")
+ check(s.i == 2, "f5 s")
}
func f6() {
- s := &S2{1};
- var i I1 = s;
- i.Put(2);
- check(i.Get() == 2, "f6 i");
- check(s.i == 2, "f6 s");
+ s := &S2{1}
+ var i I1 = s
+ i.Put(2)
+ check(i.Get() == 2, "f6 i")
+ check(s.i == 2, "f6 s")
}
-type I2 interface { Get() int64; Put(int64); }
+type I2 interface { Get() int64; Put(int64) }
type S3 struct { i, j, k, l int64 }
func (p S3) Get() int64 { return p.l }
func (p S3) Put(i int64) { p.l = i }
func f7() {
- s := S3{1, 2, 3, 4};
- var i I2 = s;
- i.Put(5);
- check(i.Get() == 4, "f7 i");
- check(s.l == 4, "f7 s");
+ s := S3{1, 2, 3, 4}
+ var i I2 = s
+ i.Put(5)
+ check(i.Get() == 4, "f7 i")
+ check(s.l == 4, "f7 s")
}
func f8() {
- s := S3{1, 2, 3, 4};
- var i I2 = &s;
- i.Put(5);
- check(i.Get() == 4, "f8 i");
- check(s.l == 4, "f8 s");
+ s := S3{1, 2, 3, 4}
+ var i I2 = &s
+ i.Put(5)
+ check(i.Get() == 4, "f8 i")
+ check(s.l == 4, "f8 s")
}
func f9() {
- s := &S3{1, 2, 3, 4};
- var i I2 = s;
- i.Put(5);
- check(i.Get() == 4, "f9 i");
- check(s.l == 4, "f9 s");
+ s := &S3{1, 2, 3, 4}
+ var i I2 = s
+ i.Put(5)
+ check(i.Get() == 4, "f9 i")
+ check(s.l == 4, "f9 s")
}
type S4 struct { i, j, k, l int64 }
@@ -114,42 +114,42 @@ func (p *S4) Put(i int64) { p.l = i }
// Disallowed by restriction of values going to pointer receivers
// func f10() {
-// s := S4{1, 2, 3, 4};
-// var i I2 = s;
-// i.Put(5);
-// check(i.Get() == 5, "f10 i");
-// check(s.l == 4, "f10 s");
+// s := S4{1, 2, 3, 4}
+// var i I2 = s
+// i.Put(5)
+// check(i.Get() == 5, "f10 i")
+// check(s.l == 4, "f10 s")
// }
func f11() {
- s := S4{1, 2, 3, 4};
- var i I2 = &s;
- i.Put(5);
- check(i.Get() == 5, "f11 i");
- check(s.l == 5, "f11 s");
+ s := S4{1, 2, 3, 4}
+ var i I2 = &s
+ i.Put(5)
+ check(i.Get() == 5, "f11 i")
+ check(s.l == 5, "f11 s")
}
func f12() {
- s := &S4{1, 2, 3, 4};
- var i I2 = s;
- i.Put(5);
- check(i.Get() == 5, "f12 i");
- check(s.l == 5, "f12 s");
+ s := &S4{1, 2, 3, 4}
+ var i I2 = s
+ i.Put(5)
+ check(i.Get() == 5, "f12 i")
+ check(s.l == 5, "f12 s")
}
func main() {
- f1();
- f2();
- f3();
-// f4();
- f5();
- f6();
- f7();
- f8();
- f9();
-// f10();
- f11();
- f12();
+ f1()
+ f2()
+ f3()
+// f4()
+ f5()
+ f6()
+ f7()
+ f8()
+ f9()
+// f10()
+ f11()
+ f12()
if fail > 0 {
os.Exit(1)
}
diff --git a/test/iota.go b/test/iota.go
index 393edac80..20b77c6cc 100644
--- a/test/iota.go
+++ b/test/iota.go
@@ -8,113 +8,113 @@ package main
func assert(cond bool, msg string) {
if !cond {
- print("assertion fail: ", msg, "\n");
- panic(1);
+ print("assertion fail: ", msg, "\n")
+ panic(1)
}
}
const (
- x int = iota;
- y = iota;
- z = 1 << iota;
- f float = 2 * iota;
- g float = 4.5 * float(iota);
+ x int = iota
+ y = iota
+ z = 1 << iota
+ f float = 2 * iota
+ g float = 4.5 * float(iota)
)
const (
- X = 0;
- Y;
- Z;
+ X = 0
+ Y
+ Z
)
const (
- A = 1 << iota;
- B;
- C;
- D;
- E = iota * iota;
- F;
- G;
+ A = 1 << iota
+ B
+ C
+ D
+ E = iota * iota
+ F
+ G
)
const (
- a = 1;
- b = iota << a;
- c = iota << b;
- d;
+ a = 1
+ b = iota << a
+ c = iota << b
+ d
)
const (
- i = (a << iota) + (b * iota);
- j;
- k;
- l;
+ i = (a << iota) + (b * iota)
+ j
+ k
+ l
)
const (
- m = iota == 0;
- n;
+ m = iota == 0
+ n
)
const (
- p = float(iota);
- q;
- r;
+ p = float(iota)
+ q
+ r
)
const (
- s = string(iota + 'a');
- t;
+ s = string(iota + 'a')
+ t
)
const (
- abit, amask = 1 << iota, 1 << iota - 1;
- bbit, bmask = 1 << iota, 1 << iota - 1;
- cbit, cmask = 1 << iota, 1 << iota - 1;
+ abit, amask = 1 << iota, 1 << iota - 1
+ bbit, bmask = 1 << iota, 1 << iota - 1
+ cbit, cmask = 1 << iota, 1 << iota - 1
)
func main() {
- assert(x == 0, "x");
- assert(y == 1, "y");
- assert(z == 4, "z");
- assert(f == 6.0, "f");
- assert(g == 18.0, "g");
-
- assert(X == 0, "X");
- assert(Y == 0, "Y");
- assert(Z == 0, "Z");
-
- assert(A == 1, "A");
- assert(B == 2, "B");
- assert(C == 4, "C");
- assert(D == 8, "D");
- assert(E == 16, "E");
- assert(F == 25, "F");
-
- assert(a == 1, "a");
- assert(b == 2, "b");
- assert(c == 8, "c");
- assert(d == 12, "d");
-
- assert(i == 1, "i");
- assert(j == 4, "j");
- assert(k == 8, "k");
- assert(l == 14, "l");
-
- assert(m, "m");
- assert(!n, "n");
-
- assert(p == 0.0, "p");
- assert(q == 1.0, "q");
- assert(r == 2.0, "r");
-
- assert(s == "a", "s");
- assert(t == "b", "t");
-
- assert(abit == 1, "abit");
- assert(amask == 0, "amask");
- assert(bbit == 2, "bbit");
- assert(bmask == 1, "bmask");
- assert(cbit == 4, "cbit");
- assert(cmask == 3, "cmask");
+ assert(x == 0, "x")
+ assert(y == 1, "y")
+ assert(z == 4, "z")
+ assert(f == 6.0, "f")
+ assert(g == 18.0, "g")
+
+ assert(X == 0, "X")
+ assert(Y == 0, "Y")
+ assert(Z == 0, "Z")
+
+ assert(A == 1, "A")
+ assert(B == 2, "B")
+ assert(C == 4, "C")
+ assert(D == 8, "D")
+ assert(E == 16, "E")
+ assert(F == 25, "F")
+
+ assert(a == 1, "a")
+ assert(b == 2, "b")
+ assert(c == 8, "c")
+ assert(d == 12, "d")
+
+ assert(i == 1, "i")
+ assert(j == 4, "j")
+ assert(k == 8, "k")
+ assert(l == 14, "l")
+
+ assert(m, "m")
+ assert(!n, "n")
+
+ assert(p == 0.0, "p")
+ assert(q == 1.0, "q")
+ assert(r == 2.0, "r")
+
+ assert(s == "a", "s")
+ assert(t == "b", "t")
+
+ assert(abit == 1, "abit")
+ assert(amask == 0, "amask")
+ assert(bbit == 2, "bbit")
+ assert(bmask == 1, "bmask")
+ assert(cbit == 4, "cbit")
+ assert(cmask == 3, "cmask")
}
diff --git a/test/ken/array.go b/test/ken/array.go
index 7785cdf8f..40209f5da 100644
--- a/test/ken/array.go
+++ b/test/ken/array.go
@@ -81,8 +81,8 @@ func testpfpf() {
// call ptr dynamic with ptr fixed from new
func testpdpf1() {
a := new([40]int)
- setpd(a)
- res(sumpd(a), 0, 40)
+ setpd(a[0:])
+ res(sumpd(a[0:]), 0, 40)
b := (*a)[5:30]
res(sumpd(b), 5, 30)
@@ -92,8 +92,8 @@ func testpdpf1() {
func testpdpf2() {
var a [80]int
- setpd(&a)
- res(sumpd(&a), 0, 80)
+ setpd(a[0:])
+ res(sumpd(a[0:]), 0, 80)
}
// generate bounds error with ptr dynamic
diff --git a/test/ken/convert.go b/test/ken/convert.go
new file mode 100644
index 000000000..3780ec886
--- /dev/null
+++ b/test/ken/convert.go
@@ -0,0 +1,431 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// 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.
+
+// near-exhaustive test of converting numbers between types.
+
+package main
+
+var i8 int8;
+var u8 uint8;
+var i16 int16;
+var u16 uint16;
+var i32 int32;
+var u32 uint32;
+var i64 int64;
+var u64 uint64;
+var f32 float32;
+var f64 float64;
+
+type big float64
+
+type t struct {
+ from, to int
+ val big
+}
+
+const (
+ ti8 = iota+1
+ tu8
+ ti16
+ tu16
+ ti32
+ tu32
+ ti64
+ tu64
+ tf32
+ tf64
+)
+
+var x = []t{
+
+ /* value good in all types (10) */
+ { ti8, ti8, 10 }, { ti8, tu8, 10 }, { ti8, ti16, 10 }, { ti8, tu16, 10 },
+ { ti8, ti32, 10 }, { ti8, tu32, 10 }, { ti8, ti64, 10 }, { ti8, tu64, 10 },
+ { ti8, tf32, 10 }, { ti8, tf64, 10 },
+
+ { tu8, ti8, 10 }, { tu8, tu8, 10 }, { tu8, ti16, 10 }, { tu8, tu16, 10 },
+ { tu8, ti32, 10 }, { tu8, tu32, 10 }, { tu8, ti64, 10 }, { tu8, tu64, 10 },
+ { tu8, tf32, 10 }, { tu8, tf64, 10 },
+
+ { ti16, ti8, 10 }, { ti16, tu8, 10 }, { ti16, ti16, 10 }, { ti16, tu16, 10 },
+ { ti16, ti32, 10 }, { ti16, tu32, 10 }, { ti16, ti64, 10 }, { ti16, tu64, 10 },
+ { ti16, tf32, 10 }, { ti16, tf64, 10 },
+
+ { tu16, ti8, 10 }, { tu16, tu8, 10 }, { tu16, ti16, 10 }, { tu16, tu16, 10 },
+ { tu16, ti32, 10 }, { tu16, tu32, 10 }, { tu16, ti64, 10 }, { tu16, tu64, 10 },
+ { tu16, tf32, 10 }, { tu16, tf64, 10 },
+
+ { ti32, ti8, 10 }, { ti32, tu8, 10 }, { ti32, ti16, 10 }, { ti32, tu16, 10 },
+ { ti32, ti32, 10 }, { ti32, tu32, 10 }, { ti32, ti64, 10 }, { ti32, tu64, 10 },
+ { ti32, tf32, 10 }, { ti32, tf64, 10 },
+
+ { tu32, ti8, 10 }, { tu32, tu8, 10 }, { tu32, ti16, 10 }, { tu32, tu16, 10 },
+ { tu32, ti32, 10 }, { tu32, tu32, 10 }, { tu32, ti64, 10 }, { tu32, tu64, 10 },
+ { tu32, tf32, 10 }, { tu32, tf64, 10 },
+
+ { ti64, ti8, 10 }, { ti64, tu8, 10 }, { ti64, ti16, 10 }, { ti64, tu16, 10 },
+ { ti64, ti32, 10 }, { ti64, tu32, 10 }, { ti64, ti64, 10 }, { ti64, tu64, 10 },
+ { ti64, tf32, 10 }, { ti64, tf64, 10 },
+
+ { tu64, ti8, 10 }, { tu64, tu8, 10 }, { tu64, ti16, 10 }, { tu64, tu16, 10 },
+ { tu64, ti32, 10 }, { tu64, tu32, 10 }, { tu64, ti64, 10 }, { tu64, tu64, 10 },
+ { tu64, tf32, 10 }, { tu64, tf64, 10 },
+
+ { tf32, ti8, 10 }, { tf32, tu8, 10 }, { tf32, ti16, 10 }, { tf32, tu16, 10 },
+ { tf32, ti32, 10 }, { tf32, tu32, 10 }, { tf32, ti64, 10 }, { tf32, tu64, 10 },
+ { tf32, tf32, 10 }, { tf32, tf64, 10 },
+
+ { tf64, ti8, 10 }, { tf64, tu8, 10 }, { tf64, ti16, 10 }, { tf64, tu16, 10 },
+ { tf64, ti32, 10 }, { tf64, tu32, 10 }, { tf64, ti64, 10 }, { tf64, tu64, 10 },
+ { tf64, tf32, 10 }, { tf64, tf64, 10 },
+
+ /* value good in all signed types (-4) */
+ { ti8, ti8, -4 }, { ti8, ti16, -4 },
+ { ti8, ti32, -4 }, { ti8, ti64, -4 },
+ { ti8, tf32, -4 }, { ti8, tf64, -4 },
+
+ { ti16, ti8, -4 }, { ti16, ti16, -4 },
+ { ti16, ti32, -4 }, { ti16, ti64, -4 },
+ { ti16, tf32, -4 },
+
+ { ti32, ti8, -4 }, { ti32, ti16, -4 },
+ { ti32, ti32, -4 }, { ti32, ti64, -4 },
+ { ti32, tf32, -4 }, { ti32, tf64, -4 },
+
+ { ti64, ti8, -4 }, { ti64, ti16, -4 },
+ { ti64, ti32, -4 }, { ti64, ti64, -4 },
+ { ti64, tf32, -4 },
+
+ { tf32, ti8, -4 }, { tf32, ti16, -4 },
+ { tf32, ti32, -4 }, { tf32, ti64, -4 },
+ { tf32, tf32, -4 },
+
+ { tf64, ti8, -4 }, { tf64, ti16, -4 },
+ { tf64, ti32, -4 }, { tf64, ti64, -4 },
+ { tf64, tf32, -4 }, { tf64, tf64, -4 },
+
+ /* value good in u8 and up (175) */
+ { tu8, tu8, 175 }, { tu8, ti16, 175 }, { tu8, tu16, 175 },
+ { tu8, ti32, 175 }, { tu8, tu32, 175 }, { tu8, ti64, 175 }, { tu8, tu64, 175 },
+ { tu8, tf32, 175 }, { tu8, tf64, 175 },
+
+ { ti16, tu8, 175 }, { ti16, ti16, 175 }, { ti16, tu16, 175 },
+ { ti16, ti32, 175 }, { ti16, tu32, 175 }, { ti16, ti64, 175 }, { ti16, tu64, 175 },
+ { ti16, tf32, 175 }, { ti16, tf64, 175 },
+
+ { tu16, tu8, 175 }, { tu16, ti16, 175 }, { tu16, tu16, 175 },
+ { tu16, ti32, 175 }, { tu16, tu32, 175 }, { tu16, ti64, 175 }, { tu16, tu64, 175 },
+ { tu16, tf32, 175 }, { tu16, tf64, 175 },
+
+ { ti32, tu8, 175 }, { ti32, ti16, 175 }, { ti32, tu16, 175 },
+ { ti32, ti32, 175 }, { ti32, tu32, 175 }, { ti32, ti64, 175 }, { ti32, tu64, 175 },
+ { ti32, tf32, 175 }, { ti32, tf64, 175 },
+
+ { tu32, tu8, 175 }, { tu32, ti16, 175 }, { tu32, tu16, 175 },
+ { tu32, ti32, 175 }, { tu32, tu32, 175 }, { tu32, ti64, 175 }, { tu32, tu64, 175 },
+ { tu32, tf32, 175 }, { tu32, tf64, 175 },
+
+ { ti64, tu8, 175 }, { ti64, ti16, 175 }, { ti64, tu16, 175 },
+ { ti64, ti32, 175 }, { ti64, tu32, 175 }, { ti64, ti64, 175 }, { ti64, tu64, 175 },
+ { ti64, tf32, 175 }, { ti64, tf64, 175 },
+
+ { tu64, tu8, 175 }, { tu64, ti16, 175 }, { tu64, tu16, 175 },
+ { tu64, ti32, 175 }, { tu64, tu32, 175 }, { tu64, ti64, 175 }, { tu64, tu64, 175 },
+ { tu64, tf32, 175 }, { tu64, tf64, 175 },
+
+ { tf32, tu8, 175 }, { tf32, ti16, 175 }, { tf32, tu16, 175 },
+ { tf32, ti32, 175 }, { tf32, tu32, 175 }, { tf32, ti64, 175 }, { tf32, tu64, 175 },
+ { tf32, tf32, 175 }, { tf32, tf64, 175 },
+
+ { tf64, tu8, 175 }, { tf64, ti16, 175 }, { tf64, tu16, 175 },
+ { tf64, ti32, 175 }, { tf64, tu32, 175 }, { tf64, ti64, 175 }, { tf64, tu64, 175 },
+ { tf64, tf32, 175 }, { tf64, tf64, 175 },
+
+ /* value good in u16 and up (41259) */
+ { tu16, tu16, 41259 },
+ { tu16, ti32, 41259 }, { tu16, ti64, 41259 }, { tu16, tu64, 41259 },
+ { tu16, tf32, 41259 }, { tu16, tf64, 41259 },
+
+ { ti32, tu16, 41259 },
+ { ti32, ti32, 41259 }, { ti32, tu32, 41259 }, { ti32, ti64, 41259 }, { ti32, tu64, 41259 },
+ { ti32, tf32, 41259 }, { ti32, tf64, 41259 },
+
+ { tu32, tu16, 41259 },
+ { tu32, ti32, 41259 }, { tu32, tu32, 41259 }, { tu32, ti64, 41259 }, { tu32, tu64, 41259 },
+ { tu32, tf32, 41259 }, { tu32, tf64, 41259 },
+
+ { ti64, tu16, 41259 },
+ { ti64, ti32, 41259 }, { ti64, tu32, 41259 }, { ti64, ti64, 41259 }, { ti64, tu64, 41259 },
+ { ti64, tf32, 41259 }, { ti64, tf64, 41259 },
+
+ { tu64, tu16, 41259 },
+ { tu64, ti32, 41259 }, { tu64, tu32, 41259 }, { tu64, ti64, 41259 }, { tu64, tu64, 41259 },
+ { tu64, tf32, 41259 }, { tu64, tf64, 41259 },
+
+ { tf32, tu16, 41259 },
+ { tf32, ti32, 41259 }, { tf32, tu32, 41259 }, { tf32, ti64, 41259 }, { tf32, tu64, 41259 },
+ { tf32, tf32, 41259 }, { tf32, tf64, 41259 },
+
+ { tf64, tu16, 41259 },
+ { tf64, ti32, 41259 }, { tf64, tu32, 41259 }, { tf64, ti64, 41259 }, { tf64, tu64, 41259 },
+ { tf64, tf32, 41259 }, { tf64, tf64, 41259 },
+
+ /* value good in u32 and up (3758096384) */
+ { tu32, tu32, 3758096384 }, { tu32, ti64, 3758096384 }, { tu32, tu64, 3758096384 },
+ { tu32, tf32, 3758096384 }, { tu32, tf64, 3758096384 },
+
+ { ti64, tu32, 3758096384 }, { ti64, ti64, 3758096384 }, { ti64, tu64, 3758096384 },
+ { ti64, tf32, 3758096384 }, { ti64, tf64, 3758096384 },
+
+ { tu64, tu32, 3758096384 }, { tu64, ti64, 3758096384 }, { tu64, tu64, 3758096384 },
+ { tu64, tf32, 3758096384 }, { tu64, tf64, 3758096384 },
+
+ { tf32, tu32, 3758096384 }, { tf32, ti64, 3758096384 }, { tf32, tu64, 3758096384 },
+ { tf32, tf32, 3758096384 }, { tf32, tf64, 3758096384 },
+
+ { tf64, tu32, 3758096384 }, { tf64, ti64, 3758096384 }, { tf64, tu64, 3758096384 },
+ { tf64, tf32, 3758096384 }, { tf64, tf64, 3758096384 },
+
+ /* value good in u64 and up (16717361816799281152) */
+ { tu64, tu64, 16717361816799281152 },
+ { tu64, tf32, 16717361816799281152 }, { tu64, tf64, 16717361816799281152 },
+
+ { tf32, tu64, 16717361816799281152 },
+ { tf32, tf32, 16717361816799281152 }, { tf32, tf64, 16717361816799281152 },
+
+ { tf64, tu64, 16717361816799281152 },
+ { tf64, tf32, 16717361816799281152 }, { tf64, tf64, 16717361816799281152 },
+}
+
+func main() {
+ for i:=0; i<len(x); i++ {
+ v := x[i].val // input value
+ w := big(0) // output value
+ f := x[i].from // input type
+ t := x[i].to // output type
+
+ i8 = 0; u8 = 0; i16 = 0; u16 = 0
+ i32 = 0; u32 = 0; i64 = 0; u64 = 0
+ f32 = 0; f64 = 0
+
+ switch f*100 + t {
+ default:
+ println("missing case", i, v, f, t)
+ w = v
+
+ case ti8*100 + ti8:
+ i8 = int8(v); i8 = int8(i8); w = big(i8)
+ case ti8*100 + tu8:
+ i8 = int8(v); u8 = uint8(i8); w = big(u8)
+ case ti8*100 + ti16:
+ i8 = int8(v); i16 = int16(i8); w = big(i16)
+ case ti8*100 + tu16:
+ i8 = int8(v); u16 = uint16(i8); w = big(u16)
+ case ti8*100 + ti32:
+ i8 = int8(v); i32 = int32(i8); w = big(i32)
+ case ti8*100 + tu32:
+ i8 = int8(v); u32 = uint32(i8); w = big(u32)
+ case ti8*100 + ti64:
+ i8 = int8(v); i64 = int64(i8); w = big(i64)
+ case ti8*100 + tu64:
+ i8 = int8(v); u64 = uint64(i8); w = big(u64)
+ case ti8*100 + tf32:
+ i8 = int8(v); f32 = float32(i8); w = big(f32)
+ case ti8*100 + tf64:
+ i8 = int8(v); f64 = float64(i8); w = big(f64)
+
+ case tu8*100 + ti8:
+ u8 = uint8(v); i8 = int8(u8); w = big(i8)
+ case tu8*100 + tu8:
+ u8 = uint8(v); u8 = uint8(u8); w = big(u8)
+ case tu8*100 + ti16:
+ u8 = uint8(v); i16 = int16(u8); w = big(i16)
+ case tu8*100 + tu16:
+ u8 = uint8(v); u16 = uint16(u8); w = big(u16)
+ case tu8*100 + ti32:
+ u8 = uint8(v); i32 = int32(u8); w = big(i32)
+ case tu8*100 + tu32:
+ u8 = uint8(v); u32 = uint32(u8); w = big(u32)
+ case tu8*100 + ti64:
+ u8 = uint8(v); i64 = int64(u8); w = big(i64)
+ case tu8*100 + tu64:
+ u8 = uint8(v); u64 = uint64(u8); w = big(u64)
+ case tu8*100 + tf32:
+ u8 = uint8(v); f32 = float32(u8); w = big(f32)
+ case tu8*100 + tf64:
+ u8 = uint8(v); f64 = float64(u8); w = big(f64)
+
+ case ti16*100 + ti8:
+ i16 = int16(v); i8 = int8(i16); w = big(i8)
+ case ti16*100 + tu8:
+ i16 = int16(v); u8 = uint8(i16); w = big(u8)
+ case ti16*100 + ti16:
+ i16 = int16(v); i16 = int16(i16); w = big(i16)
+ case ti16*100 + tu16:
+ i16 = int16(v); u16 = uint16(i16); w = big(u16)
+ case ti16*100 + ti32:
+ i16 = int16(v); i32 = int32(i16); w = big(i32)
+ case ti16*100 + tu32:
+ i16 = int16(v); u32 = uint32(i16); w = big(u32)
+ case ti16*100 + ti64:
+ i16 = int16(v); i64 = int64(i16); w = big(i64)
+ case ti16*100 + tu64:
+ i16 = int16(v); u64 = uint64(i16); w = big(u64)
+ case ti16*100 + tf32:
+ i16 = int16(v); f32 = float32(i16); w = big(f32)
+ case ti16*100 + tf64:
+ i16 = int16(v); f64 = float64(i16); w = big(f64)
+
+ case tu16*100 + ti8:
+ u16 = uint16(v); i8 = int8(u16); w = big(i8)
+ case tu16*100 + tu8:
+ u16 = uint16(v); u8 = uint8(u16); w = big(u8)
+ case tu16*100 + ti16:
+ u16 = uint16(v); i16 = int16(u16); w = big(i16)
+ case tu16*100 + tu16:
+ u16 = uint16(v); u16 = uint16(u16); w = big(u16)
+ case tu16*100 + ti32:
+ u16 = uint16(v); i32 = int32(u16); w = big(i32)
+ case tu16*100 + tu32:
+ u16 = uint16(v); u32 = uint32(u16); w = big(u32)
+ case tu16*100 + ti64:
+ u16 = uint16(v); i64 = int64(u16); w = big(i64)
+ case tu16*100 + tu64:
+ u16 = uint16(v); u64 = uint64(u16); w = big(u64)
+ case tu16*100 + tf32:
+ u16 = uint16(v); f32 = float32(u16); w = big(f32)
+ case tu16*100 + tf64:
+ u16 = uint16(v); f64 = float64(u16); w = big(f64)
+
+ case ti32*100 + ti8:
+ i32 = int32(v); i8 = int8(i32); w = big(i8)
+ case ti32*100 + tu8:
+ i32 = int32(v); u8 = uint8(i32); w = big(u8)
+ case ti32*100 + ti16:
+ i32 = int32(v); i16 = int16(i32); w = big(i16)
+ case ti32*100 + tu16:
+ i32 = int32(v); u16 = uint16(i32); w = big(u16)
+ case ti32*100 + ti32:
+ i32 = int32(v); i32 = int32(i32); w = big(i32)
+ case ti32*100 + tu32:
+ i32 = int32(v); u32 = uint32(i32); w = big(u32)
+ case ti32*100 + ti64:
+ i32 = int32(v); i64 = int64(i32); w = big(i64)
+ case ti32*100 + tu64:
+ i32 = int32(v); u64 = uint64(i32); w = big(u64)
+ case ti32*100 + tf32:
+ i32 = int32(v); f32 = float32(i32); w = big(f32)
+ case ti32*100 + tf64:
+ i32 = int32(v); f64 = float64(i32); w = big(f64)
+
+ case tu32*100 + ti8:
+ u32 = uint32(v); i8 = int8(u32); w = big(i8)
+ case tu32*100 + tu8:
+ u32 = uint32(v); u8 = uint8(u32); w = big(u8)
+ case tu32*100 + ti16:
+ u32 = uint32(v); i16 = int16(u32); w = big(i16)
+ case tu32*100 + tu16:
+ u32 = uint32(v); u16 = uint16(u32); w = big(u16)
+ case tu32*100 + ti32:
+ u32 = uint32(v); i32 = int32(u32); w = big(i32)
+ case tu32*100 + tu32:
+ u32 = uint32(v); u32 = uint32(u32); w = big(u32)
+ case tu32*100 + ti64:
+ u32 = uint32(v); i64 = int64(u32); w = big(i64)
+ case tu32*100 + tu64:
+ u32 = uint32(v); u64 = uint64(u32); w = big(u64)
+ case tu32*100 + tf32:
+ u32 = uint32(v); f32 = float32(u32); w = big(f32)
+ case tu32*100 + tf64:
+ u32 = uint32(v); f64 = float64(u32); w = big(f64)
+
+ case ti64*100 + ti8:
+ i64 = int64(v); i8 = int8(i64); w = big(i8)
+ case ti64*100 + tu8:
+ i64 = int64(v); u8 = uint8(i64); w = big(u8)
+ case ti64*100 + ti16:
+ i64 = int64(v); i16 = int16(i64); w = big(i16)
+ case ti64*100 + tu16:
+ i64 = int64(v); u16 = uint16(i64); w = big(u16)
+ case ti64*100 + ti32:
+ i64 = int64(v); i32 = int32(i64); w = big(i32)
+ case ti64*100 + tu32:
+ i64 = int64(v); u32 = uint32(i64); w = big(u32)
+ case ti64*100 + ti64:
+ i64 = int64(v); i64 = int64(i64); w = big(i64)
+ case ti64*100 + tu64:
+ i64 = int64(v); u64 = uint64(i64); w = big(u64)
+ case ti64*100 + tf32:
+ i64 = int64(v); f32 = float32(i64); w = big(f32)
+ case ti64*100 + tf64:
+ i64 = int64(v); f64 = float64(i64); w = big(f64)
+
+ case tu64*100 + ti8:
+ u64 = uint64(v); i8 = int8(u64); w = big(i8)
+ case tu64*100 + tu8:
+ u64 = uint64(v); u8 = uint8(u64); w = big(u8)
+ case tu64*100 + ti16:
+ u64 = uint64(v); i16 = int16(u64); w = big(i16)
+ case tu64*100 + tu16:
+ u64 = uint64(v); u16 = uint16(u64); w = big(u16)
+ case tu64*100 + ti32:
+ u64 = uint64(v); i32 = int32(u64); w = big(i32)
+ case tu64*100 + tu32:
+ u64 = uint64(v); u32 = uint32(u64); w = big(u32)
+ case tu64*100 + ti64:
+ u64 = uint64(v); i64 = int64(u64); w = big(i64)
+ case tu64*100 + tu64:
+ u64 = uint64(v); u64 = uint64(u64); w = big(u64)
+ case tu64*100 + tf32:
+ u64 = uint64(v); f32 = float32(u64); w = big(f32)
+ case tu64*100 + tf64:
+ u64 = uint64(v); f64 = float64(u64); w = big(f64)
+
+ case tf32*100 + ti8:
+ f32 = float32(v); i8 = int8(f32); w = big(i8)
+ case tf32*100 + tu8:
+ f32 = float32(v); u8 = uint8(f32); w = big(u8)
+ case tf32*100 + ti16:
+ f32 = float32(v); i16 = int16(f32); w = big(i16)
+ case tf32*100 + tu16:
+ f32 = float32(v); u16 = uint16(f32); w = big(u16)
+ case tf32*100 + ti32:
+ f32 = float32(v); i32 = int32(f32); w = big(i32)
+ case tf32*100 + tu32:
+ f32 = float32(v); u32 = uint32(f32); w = big(u32)
+ case tf32*100 + ti64:
+ f32 = float32(v); i64 = int64(f32); w = big(i64)
+ case tf32*100 + tu64:
+ f32 = float32(v); u64 = uint64(f32); w = big(u64)
+ case tf32*100 + tf32:
+ f32 = float32(v); f32 = float32(f32); w = big(f32)
+ case tf32*100 + tf64:
+ f32 = float32(v); f64 = float64(f32); w = big(f64)
+
+ case tf64*100 + ti8:
+ f64 = float64(v); i8 = int8(f64); w = big(i8)
+ case tf64*100 + tu8:
+ f64 = float64(v); u8 = uint8(f64); w = big(u8)
+ case tf64*100 + ti16:
+ f64 = float64(v); i16 = int16(f64); w = big(i16)
+ case tf64*100 + tu16:
+ f64 = float64(v); u16 = uint16(f64); w = big(u16)
+ case tf64*100 + ti32:
+ f64 = float64(v); i32 = int32(f64); w = big(i32)
+ case tf64*100 + tu32:
+ f64 = float64(v); u32 = uint32(f64); w = big(u32)
+ case tf64*100 + ti64:
+ f64 = float64(v); i64 = int64(f64); w = big(i64)
+ case tf64*100 + tu64:
+ f64 = float64(v); u64 = uint64(f64); w = big(u64)
+ case tf64*100 + tf32:
+ f64 = float64(v); f32 = float32(f64); w = big(f32)
+ case tf64*100 + tf64:
+ f64 = float64(v); f64 = float64(f64); w = big(f64)
+ }
+ if v != w { println(i, v, w, f, t) }
+ }
+}
diff --git a/test/ken/cplx4.go b/test/ken/cplx4.go
index d55d6a6e3..3c6f1f68c 100644
--- a/test/ken/cplx4.go
+++ b/test/ken/cplx4.go
@@ -39,6 +39,6 @@ func main() {
// compiler used to crash on nested divide
c4 := cmplx(real(c3/2), imag(c3/2))
if c4 != c3/2 {
- fmt.Printf("c3 = %G != c4 = %G\n", c3, c4)
+ fmt.Printf("BUG: c3 = %G != c4 = %G\n", c3, c4)
}
}
diff --git a/test/ken/slicearray.go b/test/ken/slicearray.go
index 76ec80931..6e7088e19 100644
--- a/test/ken/slicearray.go
+++ b/test/ken/slicearray.go
@@ -16,12 +16,12 @@ var t int
func main() {
lb = 0
hb = 10
- by = &bx
+ by = bx[0:]
tstb()
lb = 0
hb = 10
- fy = &fx
+ fy = fx[0:]
tstf()
// width 1 (byte)
@@ -33,12 +33,18 @@ func main() {
tstb()
by = bx[lb:]
tstb()
+ by = bx[:hb]
+ tstb()
by = bx[0:hb]
tstb()
by = bx[0:10]
tstb()
by = bx[0:]
tstb()
+ by = bx[:10]
+ tstb()
+ by = bx[:]
+ tstb()
lb = 2
hb = 10
@@ -65,6 +71,10 @@ func main() {
tstb()
by = bx[0:8]
tstb()
+ by = bx[:8]
+ tstb()
+ by = bx[:hb]
+ tstb()
lb = 2
hb = 8
@@ -86,12 +96,18 @@ func main() {
tstf()
fy = fx[lb:]
tstf()
+ fy = fx[:hb]
+ tstf()
fy = fx[0:hb]
tstf()
fy = fx[0:10]
tstf()
fy = fx[0:]
tstf()
+ fy = fx[:10]
+ tstf()
+ fy = fx[:]
+ tstf()
lb = 2
hb = 10
@@ -114,10 +130,14 @@ func main() {
tstf()
fy = fx[lb:8]
tstf()
+ fy = fx[:hb]
+ tstf()
fy = fx[0:hb]
tstf()
fy = fx[0:8]
tstf()
+ fy = fx[:8]
+ tstf()
lb = 2
hb = 8
diff --git a/test/ken/sliceslice.go b/test/ken/sliceslice.go
index 7e7f1b4ac..5a35acaf4 100644
--- a/test/ken/sliceslice.go
+++ b/test/ken/sliceslice.go
@@ -24,12 +24,18 @@ func main() {
tstb()
by = bx[lb:]
tstb()
+ by = bx[:hb]
+ tstb()
by = bx[0:hb]
tstb()
by = bx[0:10]
tstb()
by = bx[0:]
tstb()
+ by = bx[:10]
+ tstb()
+ by = bx[:]
+ tstb()
lb = 2
hb = 10
@@ -56,6 +62,10 @@ func main() {
tstb()
by = bx[0:8]
tstb()
+ by = bx[:8]
+ tstb()
+ by = bx[:hb]
+ tstb()
lb = 2
hb = 8
@@ -77,12 +87,18 @@ func main() {
tstf()
fy = fx[lb:]
tstf()
+ fy = fx[:hb]
+ tstf()
fy = fx[0:hb]
tstf()
fy = fx[0:10]
tstf()
fy = fx[0:]
tstf()
+ fy = fx[:10]
+ tstf()
+ fy = fx[:]
+ tstf()
lb = 2
hb = 10
@@ -105,10 +121,14 @@ func main() {
tstf()
fy = fx[lb:8]
tstf()
+ fy = fx[:hb]
+ tstf()
fy = fx[0:hb]
tstf()
fy = fx[0:8]
tstf()
+ fy = fx[:8]
+ tstf()
lb = 2
hb = 8
diff --git a/test/literal.go b/test/literal.go
index bd231eae2..9bdbabca8 100644
--- a/test/literal.go
+++ b/test/literal.go
@@ -11,212 +11,216 @@ var nbad int
func assert(cond bool, msg string) {
if !cond {
if nbad == 0 {
- print("BUG");
+ print("BUG")
}
- nbad++;
- print(" ", msg);
+ nbad++
+ print(" ", msg)
}
}
+func equal(a, b float) bool {
+ return a == b
+}
+
+
func main() {
// bool
- var t bool = true;
- var f bool = false;
- assert(t == !f, "bool");
+ var t bool = true
+ var f bool = false
+ assert(t == !f, "bool")
// int8
- var i00 int8 = 0;
- var i01 int8 = 1;
- var i02 int8 = -1;
- var i03 int8 = 127;
- var i04 int8 = -127;
- var i05 int8 = -128;
- var i06 int8 = +127;
- assert(i01 == i00 + 1, "i01");
- assert(i02 == -i01, "i02");
- assert(i03 == -i04, "i03");
- assert(-(i05+1) == i06, "i05");
+ var i00 int8 = 0
+ var i01 int8 = 1
+ var i02 int8 = -1
+ var i03 int8 = 127
+ var i04 int8 = -127
+ var i05 int8 = -128
+ var i06 int8 = +127
+ assert(i01 == i00+1, "i01")
+ assert(i02 == -i01, "i02")
+ assert(i03 == -i04, "i03")
+ assert(-(i05+1) == i06, "i05")
// int16
- var i10 int16 = 0;
- var i11 int16 = 1;
- var i12 int16 = -1;
- var i13 int16 = 32767;
- var i14 int16 = -32767;
- var i15 int16 = -32768;
- var i16 int16 = +32767;
- assert(i11 == i10 + 1, "i11");
- assert(i12 == -i11, "i12");
- assert(i13 == -i14, "i13");
- assert(-(i15+1) == i16, "i15");
+ var i10 int16 = 0
+ var i11 int16 = 1
+ var i12 int16 = -1
+ var i13 int16 = 32767
+ var i14 int16 = -32767
+ var i15 int16 = -32768
+ var i16 int16 = +32767
+ assert(i11 == i10+1, "i11")
+ assert(i12 == -i11, "i12")
+ assert(i13 == -i14, "i13")
+ assert(-(i15+1) == i16, "i15")
// int32
- var i20 int32 = 0;
- var i21 int32 = 1;
- var i22 int32 = -1;
- var i23 int32 = 2147483647;
- var i24 int32 = -2147483647;
- var i25 int32 = -2147483648;
- var i26 int32 = +2147483647;
- assert(i21 == i20 + 1, "i21");
- assert(i22 == -i21, "i22");
- assert(i23 == -i24, "i23");
- assert(-(i25+1) == i26, "i25");
- assert(i23 == (1 << 31) - 1, "i23 size");
+ var i20 int32 = 0
+ var i21 int32 = 1
+ var i22 int32 = -1
+ var i23 int32 = 2147483647
+ var i24 int32 = -2147483647
+ var i25 int32 = -2147483648
+ var i26 int32 = +2147483647
+ assert(i21 == i20+1, "i21")
+ assert(i22 == -i21, "i22")
+ assert(i23 == -i24, "i23")
+ assert(-(i25+1) == i26, "i25")
+ assert(i23 == (1<<31)-1, "i23 size")
// int64
- var i30 int64 = 0;
- var i31 int64 = 1;
- var i32 int64 = -1;
- var i33 int64 = 9223372036854775807;
- var i34 int64 = -9223372036854775807;
- var i35 int64 = -9223372036854775808;
- var i36 int64 = +9223372036854775807;
- assert(i31 == i30 + 1, "i31");
- assert(i32 == -i31, "i32");
- assert(i33 == -i34, "i33");
- assert(-(i35+1) == i36, "i35");
- assert(i33 == (1<<63) - 1, "i33 size");
+ var i30 int64 = 0
+ var i31 int64 = 1
+ var i32 int64 = -1
+ var i33 int64 = 9223372036854775807
+ var i34 int64 = -9223372036854775807
+ var i35 int64 = -9223372036854775808
+ var i36 int64 = +9223372036854775807
+ assert(i31 == i30+1, "i31")
+ assert(i32 == -i31, "i32")
+ assert(i33 == -i34, "i33")
+ assert(-(i35+1) == i36, "i35")
+ assert(i33 == (1<<63)-1, "i33 size")
// uint8
- var u00 uint8 = 0;
- var u01 uint8 = 1;
- var u02 uint8 = 255;
- var u03 uint8 = +255;
- assert(u01 == u00 + 1, "u01");
- assert(u02 == u03, "u02");
- assert(u03 == (1<<8) - 1, "u03 size");
+ var u00 uint8 = 0
+ var u01 uint8 = 1
+ var u02 uint8 = 255
+ var u03 uint8 = +255
+ assert(u01 == u00+1, "u01")
+ assert(u02 == u03, "u02")
+ assert(u03 == (1<<8)-1, "u03 size")
// uint16
- var u10 uint16 = 0;
- var u11 uint16 = 1;
- var u12 uint16 = 65535;
- var u13 uint16 = +65535;
- assert(u11 == u10 + 1, "u11");
- assert(u12 == u13, "u12");
+ var u10 uint16 = 0
+ var u11 uint16 = 1
+ var u12 uint16 = 65535
+ var u13 uint16 = +65535
+ assert(u11 == u10+1, "u11")
+ assert(u12 == u13, "u12")
// uint32
- var u20 uint32 = 0;
- var u21 uint32 = 1;
- var u22 uint32 = 4294967295;
- var u23 uint32 = +4294967295;
- assert(u21 == u20 + 1, "u21");
- assert(u22 == u23, "u22");
+ var u20 uint32 = 0
+ var u21 uint32 = 1
+ var u22 uint32 = 4294967295
+ var u23 uint32 = +4294967295
+ assert(u21 == u20+1, "u21")
+ assert(u22 == u23, "u22")
// uint64
- var u30 uint64 = 0;
- var u31 uint64 = 1;
- var u32 uint64 = 18446744073709551615;
- var u33 uint64 = +18446744073709551615;
- _, _, _, _ = u30, u31, u32, u33;
+ var u30 uint64 = 0
+ var u31 uint64 = 1
+ var u32 uint64 = 18446744073709551615
+ var u33 uint64 = +18446744073709551615
+ _, _, _, _ = u30, u31, u32, u33
// float
- var f00 float = 3.14159;
- var f01 float = -3.14159;
- var f02 float = +3.14159;
- var f03 float = 0.0;
- var f04 float = .0;
- var f05 float = 0.;
- var f06 float = -0.0;
- var f07 float = 1e10;
- var f08 float = -1e10;
- var f09 float = 1e-10;
- var f10 float = 1e+10;
- var f11 float = 1.e-10;
- var f12 float = 1.e+10;
- var f13 float = .1e-10;
- var f14 float = .1e+10;
- var f15 float = 1.1e-10;
- var f16 float = 1.1e+10;
- assert(f01 == -f00, "f01");
- assert(f02 == -f01, "f02");
- assert(f03 == f04, "f03");
- assert(f04 == f05, "f04");
- assert(f05 == f06, "f05");
- assert(f07 == -f08, "f07");
- assert(f09 == 1/f10, "f09");
- assert(f11 == f09, "f11");
- assert(f12 == f10, "f12");
- assert(f13 == f09/10.0, "f13");
- assert(f14 == f12/10.0, "f14");
- assert(f15 == f16/1e20, "f15");
+ var f00 float = 3.14159
+ var f01 float = -3.14159
+ var f02 float = +3.14159
+ var f03 float = 0.0
+ var f04 float = .0
+ var f05 float = 0.
+ var f06 float = -0.0
+ var f07 float = 1e10
+ var f08 float = -1e10
+ var f09 float = 1e-10
+ var f10 float = 1e+10
+ var f11 float = 1.e-10
+ var f12 float = 1.e+10
+ var f13 float = .1e-10
+ var f14 float = .1e+10
+ var f15 float = 1.1e-10
+ var f16 float = 1.1e+10
+ assert(f01 == -f00, "f01")
+ assert(f02 == -f01, "f02")
+ assert(f03 == f04, "f03")
+ assert(f04 == f05, "f04")
+ assert(f05 == f06, "f05")
+ assert(f07 == -f08, "f07")
+ assert(equal(f09, 1/f10), "f09")
+ assert(f11 == f09, "f11")
+ assert(f12 == f10, "f12")
+ assert(equal(f13, f09/10.0), "f13")
+ assert(equal(f14, f12/10.0), "f14")
+ assert(equal(f15, f16/1e20), "f15")
// character
- var c0 uint8 = 'a';
- var c1 uint8 = 'ä';
- var c2 uint8 = '\a';
- var c3 uint8 = '\b';
- var c4 uint8 = '\f';
- var c5 uint8 = '\n';
- var c6 uint8 = '\r';
- var c7 uint8 = '\t';
- var c8 uint8 = '\v';
- // var c9 uint8 = '本'; // correctly caught as error
- var c9 uint16 = '本';
- assert(c0 == 0x61, "c0");
- assert(c1 == 0xe4, "c1");
- assert(c2 == 0x07, "c2");
- assert(c3 == 0x08, "c3");
- assert(c4 == 0x0c, "c4");
- assert(c5 == 0x0a, "c4");
- assert(c6 == 0x0d, "c6");
- assert(c7 == 0x09, "c7");
- assert(c8 == 0x0b, "c8");
- assert(c9 == 0x672c, "c9");
-
-
- var c00 uint8 = '\000';
- var c01 uint8 = '\007';
- var c02 uint8 = '\177';
- var c03 uint8 = '\377';
- assert(c00 == 0, "c00");
- assert(c01 == 7, "c01");
- assert(c02 == 127, "c02");
- assert(c03 == 255, "c03");
-
- var cx0 uint8 = '\x00';
- var cx1 uint8 = '\x0f';
- var cx2 uint8 = '\xff';
- assert(cx0 == 0, "cx0");
- assert(cx1 == 15, "cx1");
- assert(cx2 == 255, "cx2");
-
- var cu0 uint16 = '\u1234';
- var cu1 uint32 = '\U00101234';
- assert(cu0 == 0x1234, "cu0");
- assert(cu1 == 0x101234, "cu1");
+ var c0 uint8 = 'a'
+ var c1 uint8 = 'ä'
+ var c2 uint8 = '\a'
+ var c3 uint8 = '\b'
+ var c4 uint8 = '\f'
+ var c5 uint8 = '\n'
+ var c6 uint8 = '\r'
+ var c7 uint8 = '\t'
+ var c8 uint8 = '\v'
+ // var c9 uint8 = '本' // correctly caught as error
+ var c9 uint16 = '本'
+ assert(c0 == 0x61, "c0")
+ assert(c1 == 0xe4, "c1")
+ assert(c2 == 0x07, "c2")
+ assert(c3 == 0x08, "c3")
+ assert(c4 == 0x0c, "c4")
+ assert(c5 == 0x0a, "c4")
+ assert(c6 == 0x0d, "c6")
+ assert(c7 == 0x09, "c7")
+ assert(c8 == 0x0b, "c8")
+ assert(c9 == 0x672c, "c9")
+
+ var c00 uint8 = '\000'
+ var c01 uint8 = '\007'
+ var c02 uint8 = '\177'
+ var c03 uint8 = '\377'
+ assert(c00 == 0, "c00")
+ assert(c01 == 7, "c01")
+ assert(c02 == 127, "c02")
+ assert(c03 == 255, "c03")
+
+ var cx0 uint8 = '\x00'
+ var cx1 uint8 = '\x0f'
+ var cx2 uint8 = '\xff'
+ assert(cx0 == 0, "cx0")
+ assert(cx1 == 15, "cx1")
+ assert(cx2 == 255, "cx2")
+
+ var cu0 uint16 = '\u1234'
+ var cu1 uint32 = '\U00101234'
+ assert(cu0 == 0x1234, "cu0")
+ assert(cu1 == 0x101234, "cu1")
// string
- var s0 string = "";
- var s1 string = "hellô";
- assert(s1[0] == 'h', "s1-0");
- assert(s1[4] == 0xc3, "s1-4");
- assert(s1[5] == 0xb4, "s1-5");
- var s2 string = "\a\b\f\n\r\t\v";
- _, _ = s0, s2;
-
- var s00 string = "\000";
- var s01 string = "\007";
- var s02 string = "\377";
- assert(s00[0] == 0, "s00");
- assert(s01[0] == 7, "s01");
- assert(s02[0] == 255, "s02");
-
- var x00 string = "\x00";
- var x01 string = "\x0f";
- var x02 string = "\xff";
- assert(x00[0] == 0, "x00");
- assert(x01[0] == 15, "x01");
- assert(x02[0] == 255, "x02");
+ var s0 string = ""
+ var s1 string = "hellô"
+ assert(s1[0] == 'h', "s1-0")
+ assert(s1[4] == 0xc3, "s1-4")
+ assert(s1[5] == 0xb4, "s1-5")
+ var s2 string = "\a\b\f\n\r\t\v"
+ _, _ = s0, s2
+
+ var s00 string = "\000"
+ var s01 string = "\007"
+ var s02 string = "\377"
+ assert(s00[0] == 0, "s00")
+ assert(s01[0] == 7, "s01")
+ assert(s02[0] == 255, "s02")
+
+ var x00 string = "\x00"
+ var x01 string = "\x0f"
+ var x02 string = "\xff"
+ assert(x00[0] == 0, "x00")
+ assert(x01[0] == 15, "x01")
+ assert(x02[0] == 255, "x02")
// these are all the same string
- var sj0 string = "日本語";
- var sj1 string = "\u65e5\u672c\u8a9e";
- var sj2 string = "\U000065e5\U0000672c\U00008a9e";
- var sj3 string = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e";
- assert(sj0 == sj1, "sj1");
- assert(sj0 == sj2, "sj2");
- assert(sj0 == sj3, "sj3");
+ var sj0 string = "日本語"
+ var sj1 string = "\u65e5\u672c\u8a9e"
+ var sj2 string = "\U000065e5\U0000672c\U00008a9e"
+ var sj3 string = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
+ assert(sj0 == sj1, "sj1")
+ assert(sj0 == sj2, "sj2")
+ assert(sj0 == sj3, "sj3")
if nbad > 0 {
println()
diff --git a/test/mallocrand.go b/test/mallocrand.go
index bb43e2d46..e6b422e22 100644
--- a/test/mallocrand.go
+++ b/test/mallocrand.go
@@ -56,7 +56,7 @@ func memset(b *byte, c byte, n uintptr) {
func main() {
flag.Parse()
- // prime();
+ // prime()
var blocks [1]struct {
base *byte
siz uintptr
@@ -67,7 +67,7 @@ func main() {
}
b := rand.Int() % len(blocks)
if blocks[b].base != nil {
- // println("Free", blocks[b].siz, blocks[b].base);
+ // println("Free", blocks[b].siz, blocks[b].base)
runtime.Free(blocks[b].base)
blocks[b].base = nil
allocated -= uint64(blocks[b].siz)
@@ -75,8 +75,8 @@ func main() {
}
siz := uintptr(rand.Int() >> (11 + rand.Uint32()%20))
base := runtime.Alloc(siz)
- // ptr := uintptr(syscall.BytePtr(base))+uintptr(siz/2);
- // obj, size, ref, ok := allocator.find(ptr);
+ // ptr := uintptr(syscall.BytePtr(base))+uintptr(siz/2)
+ // obj, size, ref, ok := allocator.find(ptr)
// if obj != base || *ref != 0 || !ok {
// println("find", siz, obj, ref, ok)
// panic("fail")
@@ -84,7 +84,7 @@ func main() {
blocks[b].base = base
blocks[b].siz = siz
allocated += uint64(siz)
- // println("Alloc", siz, base);
+ // println("Alloc", siz, base)
memset(base, 0xbb, siz)
bigger()
}
diff --git a/test/mallocrep.go b/test/mallocrep.go
index 2357d8375..762f3754f 100644
--- a/test/mallocrep.go
+++ b/test/mallocrep.go
@@ -31,6 +31,7 @@ func bigger() {
}
func main() {
+ runtime.GC() // clean up garbage from init
runtime.MemProfileRate = 0 // disable profiler
runtime.MemStats.Alloc = 0 // ignore stacks
flag.Parse()
@@ -59,7 +60,7 @@ func main() {
if *chatty {
println("Primed", i)
}
- // runtime.frozen = true;
+ // runtime.frozen = true
}
}
}
diff --git a/test/map.go b/test/map.go
index 4905f6e11..ddff7c7a7 100644
--- a/test/map.go
+++ b/test/map.go
@@ -7,318 +7,318 @@
package main
import (
- "fmt";
- "strconv";
+ "fmt"
+ "strconv"
)
-const count = 100;
+const count = 100
func P(a []string) string {
- s := "{";
+ s := "{"
for i := 0; i < len(a); i++ {
if i > 0 {
s += ","
}
- s += `"` + a[i] + `"`;
+ s += `"` + a[i] + `"`
}
- s +="}";
- return s;
+ s +="}"
+ return s
}
func main() {
// Test a map literal.
- mlit := map[string] int { "0":0, "1":1, "2":2, "3":3, "4":4 };
+ mlit := map[string] int { "0":0, "1":1, "2":2, "3":3, "4":4 }
for i := 0; i < len(mlit); i++ {
- s := string([]byte{byte(i)+'0'});
+ s := string([]byte{byte(i)+'0'})
if mlit[s] != i {
fmt.Printf("mlit[%s] = %d\n", s, mlit[s])
}
}
- mib := make(map[int] bool);
- mii := make(map[int] int);
- mfi := make(map[float] int);
- mif := make(map[int] float);
- msi := make(map[string] int);
- mis := make(map[int] string);
- mss := make(map[string] string);
- mspa := make(map[string] []string);
+ mib := make(map[int] bool)
+ mii := make(map[int] int)
+ mfi := make(map[float] int)
+ mif := make(map[int] float)
+ msi := make(map[string] int)
+ mis := make(map[int] string)
+ mss := make(map[string] string)
+ mspa := make(map[string] []string)
// BUG need an interface map both ways too
type T struct {
- i int64; // can't use string here; struct values are only compared at the top level
- f float;
- };
- mipT := make(map[int] *T);
- mpTi := make(map[*T] int);
- mit := make(map[int] T);
-// mti := make(map[T] int);
+ i int64 // can't use string here; struct values are only compared at the top level
+ f float
+ }
+ mipT := make(map[int] *T)
+ mpTi := make(map[*T] int)
+ mit := make(map[int] T)
+// mti := make(map[T] int)
- type M map[int] int;
- mipM := make(map[int] M);
+ type M map[int] int
+ mipM := make(map[int] M)
- var apT [2*count]*T;
+ var apT [2*count]*T
for i := 0; i < count; i++ {
- s := strconv.Itoa(i);
- s10 := strconv.Itoa(i*10);
- f := float(i);
- t := T{int64(i),f};
- apT[i] = new(T);
- apT[i].i = int64(i);
- apT[i].f = f;
- apT[2*i] = new(T); // need twice as many entries as we use, for the nonexistence check
- apT[2*i].i = int64(i);
- apT[2*i].f = f;
- m := M{i: i+1};
- mib[i] = (i != 0);
- mii[i] = 10*i;
- mfi[float(i)] = 10*i;
- mif[i] = 10.0*f;
- mis[i] = s;
- msi[s] = i;
- mss[s] = s10;
- mss[s] = s10;
- as := make([]string, 2);
- as[0] = s10;
- as[1] = s10;
- mspa[s] = as;
- mipT[i] = apT[i];
- mpTi[apT[i]] = i;
- mipM[i] = m;
- mit[i] = t;
- // mti[t] = i;
+ s := strconv.Itoa(i)
+ s10 := strconv.Itoa(i*10)
+ f := float(i)
+ t := T{int64(i),f}
+ apT[i] = new(T)
+ apT[i].i = int64(i)
+ apT[i].f = f
+ apT[2*i] = new(T) // need twice as many entries as we use, for the nonexistence check
+ apT[2*i].i = int64(i)
+ apT[2*i].f = f
+ m := M{i: i+1}
+ mib[i] = (i != 0)
+ mii[i] = 10*i
+ mfi[float(i)] = 10*i
+ mif[i] = 10.0*f
+ mis[i] = s
+ msi[s] = i
+ mss[s] = s10
+ mss[s] = s10
+ as := make([]string, 2)
+ as[0] = s10
+ as[1] = s10
+ mspa[s] = as
+ mipT[i] = apT[i]
+ mpTi[apT[i]] = i
+ mipM[i] = m
+ mit[i] = t
+ // mti[t] = i
}
// test len
if len(mib) != count {
- fmt.Printf("len(mib) = %d\n", len(mib));
+ fmt.Printf("len(mib) = %d\n", len(mib))
}
if len(mii) != count {
- fmt.Printf("len(mii) = %d\n", len(mii));
+ fmt.Printf("len(mii) = %d\n", len(mii))
}
if len(mfi) != count {
- fmt.Printf("len(mfi) = %d\n", len(mfi));
+ fmt.Printf("len(mfi) = %d\n", len(mfi))
}
if len(mif) != count {
- fmt.Printf("len(mif) = %d\n", len(mif));
+ fmt.Printf("len(mif) = %d\n", len(mif))
}
if len(msi) != count {
- fmt.Printf("len(msi) = %d\n", len(msi));
+ fmt.Printf("len(msi) = %d\n", len(msi))
}
if len(mis) != count {
- fmt.Printf("len(mis) = %d\n", len(mis));
+ fmt.Printf("len(mis) = %d\n", len(mis))
}
if len(mss) != count {
- fmt.Printf("len(mss) = %d\n", len(mss));
+ fmt.Printf("len(mss) = %d\n", len(mss))
}
if len(mspa) != count {
- fmt.Printf("len(mspa) = %d\n", len(mspa));
+ fmt.Printf("len(mspa) = %d\n", len(mspa))
}
if len(mipT) != count {
- fmt.Printf("len(mipT) = %d\n", len(mipT));
+ fmt.Printf("len(mipT) = %d\n", len(mipT))
}
if len(mpTi) != count {
- fmt.Printf("len(mpTi) = %d\n", len(mpTi));
+ fmt.Printf("len(mpTi) = %d\n", len(mpTi))
}
// if len(mti) != count {
-// fmt.Printf("len(mti) = %d\n", len(mti));
+// fmt.Printf("len(mti) = %d\n", len(mti))
// }
if len(mipM) != count {
- fmt.Printf("len(mipM) = %d\n", len(mipM));
+ fmt.Printf("len(mipM) = %d\n", len(mipM))
}
// if len(mti) != count {
-// fmt.Printf("len(mti) = %d\n", len(mti));
+// fmt.Printf("len(mti) = %d\n", len(mti))
// }
if len(mit) != count {
- fmt.Printf("len(mit) = %d\n", len(mit));
+ fmt.Printf("len(mit) = %d\n", len(mit))
}
// test construction directly
for i := 0; i < count; i++ {
- s := strconv.Itoa(i);
- s10 := strconv.Itoa(i*10);
- f := float(i);
- // BUG m := M(i, i+1);
+ s := strconv.Itoa(i)
+ s10 := strconv.Itoa(i*10)
+ f := float(i)
+ // BUG m := M(i, i+1)
if mib[i] != (i != 0) {
- fmt.Printf("mib[%d] = %t\n", i, mib[i]);
+ fmt.Printf("mib[%d] = %t\n", i, mib[i])
}
if(mii[i] != 10*i) {
- fmt.Printf("mii[%d] = %d\n", i, mii[i]);
+ fmt.Printf("mii[%d] = %d\n", i, mii[i])
}
if(mfi[f] != 10*i) {
- fmt.Printf("mfi[%d] = %d\n", i, mfi[f]);
+ fmt.Printf("mfi[%d] = %d\n", i, mfi[f])
}
if(mif[i] != 10.0*f) {
- fmt.Printf("mif[%d] = %g\n", i, mif[i]);
+ fmt.Printf("mif[%d] = %g\n", i, mif[i])
}
if(mis[i] != s) {
- fmt.Printf("mis[%d] = %s\n", i, mis[i]);
+ fmt.Printf("mis[%d] = %s\n", i, mis[i])
}
if(msi[s] != i) {
- fmt.Printf("msi[%s] = %d\n", s, msi[s]);
+ fmt.Printf("msi[%s] = %d\n", s, msi[s])
}
if mss[s] != s10 {
- fmt.Printf("mss[%s] = %g\n", s, mss[s]);
+ fmt.Printf("mss[%s] = %g\n", s, mss[s])
}
for j := 0; j < len(mspa[s]); j++ {
if mspa[s][j] != s10 {
- fmt.Printf("mspa[%s][%d] = %s\n", s, j, mspa[s][j]);
+ fmt.Printf("mspa[%s][%d] = %s\n", s, j, mspa[s][j])
}
}
if(mipT[i].i != int64(i) || mipT[i].f != f) {
- fmt.Printf("mipT[%d] = %v\n", i, mipT[i]);
+ fmt.Printf("mipT[%d] = %v\n", i, mipT[i])
}
if(mpTi[apT[i]] != i) {
- fmt.Printf("mpTi[apT[%d]] = %d\n", i, mpTi[apT[i]]);
+ fmt.Printf("mpTi[apT[%d]] = %d\n", i, mpTi[apT[i]])
}
// if(mti[t] != i) {
- // fmt.Printf("mti[%s] = %s\n", s, mti[t]);
+ // fmt.Printf("mti[%s] = %s\n", s, mti[t])
// }
if (mipM[i][i] != i + 1) {
- fmt.Printf("mipM[%d][%d] = %d\n", i, i, mipM[i][i]);
+ fmt.Printf("mipM[%d][%d] = %d\n", i, i, mipM[i][i])
}
// if(mti[t] != i) {
- // fmt.Printf("mti[%v] = %d\n", t, mti[t]);
+ // fmt.Printf("mti[%v] = %d\n", t, mti[t])
// }
if(mit[i].i != int64(i) || mit[i].f != f) {
- fmt.Printf("mit[%d] = {%d %g}\n", i, mit[i].i, mit[i].f);
+ fmt.Printf("mit[%d] = {%d %g}\n", i, mit[i].i, mit[i].f)
}
}
// test existence with tuple check
// failed lookups yield a false value for the boolean.
for i := 0; i < count; i++ {
- s := strconv.Itoa(i);
- f := float(i);
+ s := strconv.Itoa(i)
+ f := float(i)
{
- _, b := mib[i];
+ _, b := mib[i]
if !b {
- fmt.Printf("tuple existence decl: mib[%d]\n", i);
+ fmt.Printf("tuple existence decl: mib[%d]\n", i)
}
- _, b = mib[i];
+ _, b = mib[i]
if !b {
- fmt.Printf("tuple existence assign: mib[%d]\n", i);
+ fmt.Printf("tuple existence assign: mib[%d]\n", i)
}
}
{
- _, b := mii[i];
+ _, b := mii[i]
if !b {
- fmt.Printf("tuple existence decl: mii[%d]\n", i);
+ fmt.Printf("tuple existence decl: mii[%d]\n", i)
}
- _, b = mii[i];
+ _, b = mii[i]
if !b {
- fmt.Printf("tuple existence assign: mii[%d]\n", i);
+ fmt.Printf("tuple existence assign: mii[%d]\n", i)
}
}
{
- _, b := mfi[f];
+ _, b := mfi[f]
if !b {
- fmt.Printf("tuple existence decl: mfi[%d]\n", i);
+ fmt.Printf("tuple existence decl: mfi[%d]\n", i)
}
- _, b = mfi[f];
+ _, b = mfi[f]
if !b {
- fmt.Printf("tuple existence assign: mfi[%d]\n", i);
+ fmt.Printf("tuple existence assign: mfi[%d]\n", i)
}
}
{
- _, b := mif[i];
+ _, b := mif[i]
if !b {
- fmt.Printf("tuple existence decl: mif[%d]\n", i);
+ fmt.Printf("tuple existence decl: mif[%d]\n", i)
}
- _, b = mif[i];
+ _, b = mif[i]
if !b {
- fmt.Printf("tuple existence assign: mif[%d]\n", i);
+ fmt.Printf("tuple existence assign: mif[%d]\n", i)
}
}
{
- _, b := mis[i];
+ _, b := mis[i]
if !b {
- fmt.Printf("tuple existence decl: mis[%d]\n", i);
+ fmt.Printf("tuple existence decl: mis[%d]\n", i)
}
- _, b = mis[i];
+ _, b = mis[i]
if !b {
- fmt.Printf("tuple existence assign: mis[%d]\n", i);
+ fmt.Printf("tuple existence assign: mis[%d]\n", i)
}
}
{
- _, b := msi[s];
+ _, b := msi[s]
if !b {
- fmt.Printf("tuple existence decl: msi[%d]\n", i);
+ fmt.Printf("tuple existence decl: msi[%d]\n", i)
}
- _, b = msi[s];
+ _, b = msi[s]
if !b {
- fmt.Printf("tuple existence assign: msi[%d]\n", i);
+ fmt.Printf("tuple existence assign: msi[%d]\n", i)
}
}
{
- _, b := mss[s];
+ _, b := mss[s]
if !b {
- fmt.Printf("tuple existence decl: mss[%d]\n", i);
+ fmt.Printf("tuple existence decl: mss[%d]\n", i)
}
- _, b = mss[s];
+ _, b = mss[s]
if !b {
- fmt.Printf("tuple existence assign: mss[%d]\n", i);
+ fmt.Printf("tuple existence assign: mss[%d]\n", i)
}
}
{
- _, b := mspa[s];
+ _, b := mspa[s]
if !b {
- fmt.Printf("tuple existence decl: mspa[%d]\n", i);
+ fmt.Printf("tuple existence decl: mspa[%d]\n", i)
}
- _, b = mspa[s];
+ _, b = mspa[s]
if !b {
- fmt.Printf("tuple existence assign: mspa[%d]\n", i);
+ fmt.Printf("tuple existence assign: mspa[%d]\n", i)
}
}
{
- _, b := mipT[i];
+ _, b := mipT[i]
if !b {
- fmt.Printf("tuple existence decl: mipT[%d]\n", i);
+ fmt.Printf("tuple existence decl: mipT[%d]\n", i)
}
- _, b = mipT[i];
+ _, b = mipT[i]
if !b {
- fmt.Printf("tuple existence assign: mipT[%d]\n", i);
+ fmt.Printf("tuple existence assign: mipT[%d]\n", i)
}
}
{
- _, b := mpTi[apT[i]];
+ _, b := mpTi[apT[i]]
if !b {
- fmt.Printf("tuple existence decl: mpTi[apT[%d]]\n", i);
+ fmt.Printf("tuple existence decl: mpTi[apT[%d]]\n", i)
}
- _, b = mpTi[apT[i]];
+ _, b = mpTi[apT[i]]
if !b {
- fmt.Printf("tuple existence assign: mpTi[apT[%d]]\n", i);
+ fmt.Printf("tuple existence assign: mpTi[apT[%d]]\n", i)
}
}
{
- _, b := mipM[i];
+ _, b := mipM[i]
if !b {
- fmt.Printf("tuple existence decl: mipM[%d]\n", i);
+ fmt.Printf("tuple existence decl: mipM[%d]\n", i)
}
- _, b = mipM[i];
+ _, b = mipM[i]
if !b {
- fmt.Printf("tuple existence assign: mipM[%d]\n", i);
+ fmt.Printf("tuple existence assign: mipM[%d]\n", i)
}
}
{
- _, b := mit[i];
+ _, b := mit[i]
if !b {
- fmt.Printf("tuple existence decl: mit[%d]\n", i);
+ fmt.Printf("tuple existence decl: mit[%d]\n", i)
}
- _, b = mit[i];
+ _, b = mit[i]
if !b {
- fmt.Printf("tuple existence assign: mit[%d]\n", i);
+ fmt.Printf("tuple existence assign: mit[%d]\n", i)
}
}
// {
-// _, b := mti[t];
+// _, b := mti[t]
// if !b {
-// fmt.Printf("tuple existence decl: mti[%d]\n", i);
+// fmt.Printf("tuple existence decl: mti[%d]\n", i)
// }
-// _, b = mti[t];
+// _, b = mti[t]
// if !b {
-// fmt.Printf("tuple existence assign: mti[%d]\n", i);
+// fmt.Printf("tuple existence assign: mti[%d]\n", i)
// }
// }
}
@@ -326,136 +326,136 @@ func main() {
// test nonexistence with tuple check
// failed lookups yield a false value for the boolean.
for i := count; i < 2*count; i++ {
- s := strconv.Itoa(i);
- f := float(i);
+ s := strconv.Itoa(i)
+ f := float(i)
{
- _, b := mib[i];
+ _, b := mib[i]
if b {
- fmt.Printf("tuple nonexistence decl: mib[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mib[%d]", i)
}
- _, b = mib[i];
+ _, b = mib[i]
if b {
- fmt.Printf("tuple nonexistence assign: mib[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mib[%d]", i)
}
}
{
- _, b := mii[i];
+ _, b := mii[i]
if b {
- fmt.Printf("tuple nonexistence decl: mii[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mii[%d]", i)
}
- _, b = mii[i];
+ _, b = mii[i]
if b {
- fmt.Printf("tuple nonexistence assign: mii[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mii[%d]", i)
}
}
{
- _, b := mfi[f];
+ _, b := mfi[f]
if b {
- fmt.Printf("tuple nonexistence decl: mfi[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mfi[%d]", i)
}
- _, b = mfi[f];
+ _, b = mfi[f]
if b {
- fmt.Printf("tuple nonexistence assign: mfi[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mfi[%d]", i)
}
}
{
- _, b := mif[i];
+ _, b := mif[i]
if b {
- fmt.Printf("tuple nonexistence decl: mif[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mif[%d]", i)
}
- _, b = mif[i];
+ _, b = mif[i]
if b {
- fmt.Printf("tuple nonexistence assign: mif[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mif[%d]", i)
}
}
{
- _, b := mis[i];
+ _, b := mis[i]
if b {
- fmt.Printf("tuple nonexistence decl: mis[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mis[%d]", i)
}
- _, b = mis[i];
+ _, b = mis[i]
if b {
- fmt.Printf("tuple nonexistence assign: mis[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mis[%d]", i)
}
}
{
- _, b := msi[s];
+ _, b := msi[s]
if b {
- fmt.Printf("tuple nonexistence decl: msi[%d]", i);
+ fmt.Printf("tuple nonexistence decl: msi[%d]", i)
}
- _, b = msi[s];
+ _, b = msi[s]
if b {
- fmt.Printf("tuple nonexistence assign: msi[%d]", i);
+ fmt.Printf("tuple nonexistence assign: msi[%d]", i)
}
}
{
- _, b := mss[s];
+ _, b := mss[s]
if b {
- fmt.Printf("tuple nonexistence decl: mss[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mss[%d]", i)
}
- _, b = mss[s];
+ _, b = mss[s]
if b {
- fmt.Printf("tuple nonexistence assign: mss[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mss[%d]", i)
}
}
{
- _, b := mspa[s];
+ _, b := mspa[s]
if b {
- fmt.Printf("tuple nonexistence decl: mspa[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mspa[%d]", i)
}
- _, b = mspa[s];
+ _, b = mspa[s]
if b {
- fmt.Printf("tuple nonexistence assign: mspa[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mspa[%d]", i)
}
}
{
- _, b := mipT[i];
+ _, b := mipT[i]
if b {
- fmt.Printf("tuple nonexistence decl: mipT[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mipT[%d]", i)
}
- _, b = mipT[i];
+ _, b = mipT[i]
if b {
- fmt.Printf("tuple nonexistence assign: mipT[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mipT[%d]", i)
}
}
{
- _, b := mpTi[apT[i]];
+ _, b := mpTi[apT[i]]
if b {
- fmt.Printf("tuple nonexistence decl: mpTi[apt[%d]]", i);
+ fmt.Printf("tuple nonexistence decl: mpTi[apt[%d]]", i)
}
- _, b = mpTi[apT[i]];
+ _, b = mpTi[apT[i]]
if b {
- fmt.Printf("tuple nonexistence assign: mpTi[apT[%d]]", i);
+ fmt.Printf("tuple nonexistence assign: mpTi[apT[%d]]", i)
}
}
{
- _, b := mipM[i];
+ _, b := mipM[i]
if b {
- fmt.Printf("tuple nonexistence decl: mipM[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mipM[%d]", i)
}
- _, b = mipM[i];
+ _, b = mipM[i]
if b {
- fmt.Printf("tuple nonexistence assign: mipM[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mipM[%d]", i)
}
}
// {
-// _, b := mti[t];
+// _, b := mti[t]
// if b {
-// fmt.Printf("tuple nonexistence decl: mti[%d]", i);
+// fmt.Printf("tuple nonexistence decl: mti[%d]", i)
// }
-// _, b = mti[t];
+// _, b = mti[t]
// if b {
-// fmt.Printf("tuple nonexistence assign: mti[%d]", i);
+// fmt.Printf("tuple nonexistence assign: mti[%d]", i)
// }
// }
{
- _, b := mit[i];
+ _, b := mit[i]
if b {
- fmt.Printf("tuple nonexistence decl: mit[%d]", i);
+ fmt.Printf("tuple nonexistence decl: mit[%d]", i)
}
- _, b = mit[i];
+ _, b = mit[i]
if b {
- fmt.Printf("tuple nonexistence assign: mit[%d]", i);
+ fmt.Printf("tuple nonexistence assign: mit[%d]", i)
}
}
}
@@ -463,30 +463,30 @@ func main() {
// tests for structured map element updates
for i := 0; i < count; i++ {
- s := strconv.Itoa(i);
- mspa[s][i % 2] = "deleted";
+ s := strconv.Itoa(i)
+ mspa[s][i % 2] = "deleted"
if mspa[s][i % 2] != "deleted" {
- fmt.Printf("update mspa[%s][%d] = %s\n", s, i %2, mspa[s][i % 2]);
+ fmt.Printf("update mspa[%s][%d] = %s\n", s, i %2, mspa[s][i % 2])
}
- mipT[i].i += 1;
+ mipT[i].i += 1
if mipT[i].i != int64(i)+1 {
- fmt.Printf("update mipT[%d].i = %d\n", i, mipT[i].i);
+ fmt.Printf("update mipT[%d].i = %d\n", i, mipT[i].i)
}
- mipT[i].f = float(i + 1);
+ mipT[i].f = float(i + 1)
if (mipT[i].f != float(i + 1)) {
- fmt.Printf("update mipT[%d].f = %g\n", i, mipT[i].f);
+ fmt.Printf("update mipT[%d].f = %g\n", i, mipT[i].f)
}
- mipM[i][i]++;
+ mipM[i][i]++
if mipM[i][i] != (i + 1) + 1 {
- fmt.Printf("update mipM[%d][%d] = %i\n", i, i, mipM[i][i]);
+ fmt.Printf("update mipM[%d][%d] = %i\n", i, i, mipM[i][i])
}
}
// test range on nil map
- var mnil map[string] int;
+ var mnil map[string] int
for _, _ = range mnil {
- panic("range mnil");
+ panic("range mnil")
}
}
diff --git a/test/method.go b/test/method.go
index c751c1f1b..b5a02c687 100644
--- a/test/method.go
+++ b/test/method.go
@@ -19,7 +19,7 @@ func (s S) val() int { return 1 }
func (s *S1) val() int { return 2 }
func (i I) val() int { return 3 }
func (i *I1) val() int { return 4 }
-//func (t T) val() int { return 7 }
+func (t T) val() int { return 7 }
func (t *T1) val() int { return 8 }
type Val interface {
@@ -34,6 +34,8 @@ func main() {
var i I
var pi *I1
var pt *T1
+ var t T
+ var v Val
if s.val() != 1 {
println("s.val:", s.val())
@@ -75,7 +77,10 @@ func main() {
println("(*I1).val(pi):", (*I1).val(pi))
panic("fail")
}
- // if t.val() != 7 { prinln("t.val:", t.val()); panic("fail") }
+ if t.val() != 7 {
+ println("t.val:", t.val())
+ panic("fail")
+ }
if pt.val() != 8 {
println("pt.val:", pt.val())
panic("fail")
@@ -101,11 +106,22 @@ func main() {
println("pi.val:", val(pi))
panic("fail")
}
- // if val(t) != 7 { println("t.val:", val(t)); panic("fail") }
+ if val(t) != 7 {
+ println("t.val:", val(t))
+ panic("fail")
+ }
if val(pt) != 8 {
println("pt.val:", val(pt))
panic("fail")
}
- // if Val.val(i) != 3 { println("Val.val(i):", Val.val(i)); panic("fail") }
+ if Val.val(i) != 3 {
+ println("Val.val(i):", Val.val(i))
+ panic("fail")
+ }
+ v = i
+ if Val.val(v) != 3 {
+ println("Val.val(v):", Val.val(v))
+ panic("fail")
+ }
}
diff --git a/test/method1.go b/test/method1.go
index a562e3663..1a2f8cae5 100644
--- a/test/method1.go
+++ b/test/method1.go
@@ -7,11 +7,11 @@
package main
type T struct { }
-func (t *T) M(int, string); // GCCGO_ERROR "previous"
+func (t *T) M(int, string) // GCCGO_ERROR "previous"
func (t *T) M(int, float) { } // ERROR "redeclared|redefinition"
-func f(int, string); // GCCGO_ERROR "previous"
+func f(int, string) // GCCGO_ERROR "previous"
func f(int, float) { } // ERROR "redeclared|redefinition"
-func g(a int, b string); // GCCGO_ERROR "previous"
-func g(a int, c string); // ERROR "redeclared|redefinition"
+func g(a int, b string) // GCCGO_ERROR "previous"
+func g(a int, c string) // ERROR "redeclared|redefinition"
diff --git a/test/method2.go b/test/method2.go
index 3ee0ae136..a72536e7b 100644
--- a/test/method2.go
+++ b/test/method2.go
@@ -6,9 +6,22 @@
package main
-type T struct {a int}
+type T struct {
+ a int
+}
type P *T
type P1 *T
-func (p P) val() int { return 1 } // ERROR "receiver"
-func (p *P1) val() int { return 1 } // ERROR "receiver"
+func (p P) val() int { return 1 } // ERROR "receiver"
+func (p *P1) val() int { return 1 } // ERROR "receiver"
+
+type Val interface {
+ val() int
+}
+
+var _ = (*Val).val // ERROR "method"
+
+var v Val
+var pv = &v
+
+var _ = pv.val() // ERROR "method"
diff --git a/test/named1.go b/test/named1.go
index 241697d5c..600e502f9 100644
--- a/test/named1.go
+++ b/test/named1.go
@@ -64,5 +64,5 @@ func main() {
b = closed(c) // ERROR "cannot use.*type bool.*type Bool"
_ = b
- asString(String(slice)) // ERROR "cannot convert slice"
+ asString(String(slice)) // ERROR "cannot .*type Slice.*type String"
}
diff --git a/test/nil.go b/test/nil.go
index d35309615..6a72b72eb 100644
--- a/test/nil.go
+++ b/test/nil.go
@@ -14,24 +14,24 @@ type IN interface {
}
func main() {
- var i *int;
- var f *float;
- var s *string;
- var m map[float] *int;
- var c chan int;
- var t *T;
- var in IN;
- var ta []IN;
+ var i *int
+ var f *float
+ var s *string
+ var m map[float] *int
+ var c chan int
+ var t *T
+ var in IN
+ var ta []IN
- i = nil;
- f = nil;
- s = nil;
- m = nil;
- c = nil;
- t = nil;
- i = nil;
- ta = make([]IN, 1);
- ta[0] = nil;
+ i = nil
+ f = nil
+ s = nil
+ m = nil
+ c = nil
+ t = nil
+ i = nil
+ ta = make([]IN, 1)
+ ta[0] = nil
- _, _, _, _, _, _, _, _ = i, f, s, m, c, t, in, ta;
+ _, _, _, _, _, _, _, _ = i, f, s, m, c, t, in, ta
}
diff --git a/test/nilptr/arrayindex.go b/test/nilptr/arrayindex.go
index 1767acc27..fa26532c6 100644
--- a/test/nilptr/arrayindex.go
+++ b/test/nilptr/arrayindex.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -13,8 +12,8 @@ import "unsafe"
var x byte
func main() {
- var p *[1<<30]byte = nil;
- x = 123;
+ var p *[1<<30]byte = nil
+ x = 123
// The problem here is not the use of unsafe:
// it is that indexing into p[] with a large
@@ -23,5 +22,5 @@ func main() {
// Pointer offsets and array indices, if they are
// very large, need to dereference the base pointer
// to trigger a trap.
- println(p[uintptr(unsafe.Pointer(&x))]); // should crash
+ println(p[uintptr(unsafe.Pointer(&x))]) // should crash
}
diff --git a/test/nilptr/arrayindex1.go b/test/nilptr/arrayindex1.go
index c16cac405..64f46e14d 100644
--- a/test/nilptr/arrayindex1.go
+++ b/test/nilptr/arrayindex1.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -10,7 +9,7 @@ package main
import "unsafe"
-var dummy [512<<20]byte; // give us a big address space
+var dummy [512<<20]byte // give us a big address space
func main() {
// the test only tests what we intend to test
// if dummy starts in the first 256 MB of memory.
@@ -18,7 +17,7 @@ func main() {
// at the address that might be accidentally
// dereferenced below.
if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
- panic("dummy too far out");
+ panic("dummy too far out")
}
// The problem here is that indexing into p[] with a large
@@ -27,6 +26,6 @@ func main() {
// Pointer offsets and array indices, if they are
// very large, need to dereference the base pointer
// to trigger a trap.
- var p *[1<<30]byte = nil;
- println(p[256<<20]); // very likely to be inside dummy, but should crash
+ var p *[1<<30]byte = nil
+ println(p[256<<20]) // very likely to be inside dummy, but should crash
}
diff --git a/test/nilptr/arraytoslice.go b/test/nilptr/arraytoslice.go
index 65b2f8a76..03879fb42 100644
--- a/test/nilptr/arraytoslice.go
+++ b/test/nilptr/arraytoslice.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -11,10 +10,10 @@ package main
import "unsafe"
func f([]byte) {
- panic("unreachable");
+ panic("unreachable")
}
-var dummy [512<<20]byte; // give us a big address space
+var dummy [512<<20]byte // give us a big address space
func main() {
// the test only tests what we intend to test
// if dummy starts in the first 256 MB of memory.
@@ -22,7 +21,7 @@ func main() {
// at the address that might be accidentally
// dereferenced below.
if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
- panic("dummy too far out");
+ panic("dummy too far out")
}
// The problem here is that indexing into p[] with a large
@@ -32,6 +31,6 @@ func main() {
// To avoid needing a check on every slice beyond the
// usual len and cap, we require the *array -> slice
// conversion to do the check.
- var p *[1<<30]byte = nil;
- f(p); // should crash
+ var p *[1<<30]byte = nil
+ f(p[0:]) // should crash
}
diff --git a/test/nilptr/arraytoslice1.go b/test/nilptr/arraytoslice1.go
index b5240a803..c86070fa4 100644
--- a/test/nilptr/arraytoslice1.go
+++ b/test/nilptr/arraytoslice1.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -10,7 +9,7 @@ package main
import "unsafe"
-var dummy [512<<20]byte; // give us a big address space
+var dummy [512<<20]byte // give us a big address space
func main() {
// the test only tests what we intend to test
// if dummy starts in the first 256 MB of memory.
@@ -18,7 +17,7 @@ func main() {
// at the address that might be accidentally
// dereferenced below.
if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
- panic("dummy too far out");
+ panic("dummy too far out")
}
// The problem here is that indexing into p[] with a large
@@ -28,7 +27,7 @@ func main() {
// To avoid needing a check on every slice beyond the
// usual len and cap, we require the *array -> slice
// conversion to do the check.
- var p *[1<<30]byte = nil;
- var x []byte = p; // should crash
- _ = x;
+ var p *[1<<30]byte = nil
+ var x []byte = p[0:] // should crash
+ _ = x
}
diff --git a/test/nilptr/arraytoslice2.go b/test/nilptr/arraytoslice2.go
index 38e1a5cb2..68ea44083 100644
--- a/test/nilptr/arraytoslice2.go
+++ b/test/nilptr/arraytoslice2.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -10,8 +9,8 @@ package main
import "unsafe"
-var dummy [512<<20]byte; // give us a big address space
-var q *[1<<30]byte;
+var dummy [512<<20]byte // give us a big address space
+var q *[1<<30]byte
func main() {
// the test only tests what we intend to test
// if dummy starts in the first 256 MB of memory.
@@ -19,7 +18,7 @@ func main() {
// at the address that might be accidentally
// dereferenced below.
if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
- panic("dummy too far out");
+ panic("dummy too far out")
}
// The problem here is that indexing into p[] with a large
@@ -29,7 +28,7 @@ func main() {
// To avoid needing a check on every slice beyond the
// usual len and cap, we require the *array -> slice
// conversion to do the check.
- var x []byte;
- var y = &x;
- *y = q; // should crash (uses arraytoslice runtime routine)
+ var x []byte
+ var y = &x
+ *y = q[0:] // should crash (uses arraytoslice runtime routine)
}
diff --git a/test/nilptr/slicearray.go b/test/nilptr/slicearray.go
index 5f88010df..26ca42773 100644
--- a/test/nilptr/slicearray.go
+++ b/test/nilptr/slicearray.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -10,7 +9,7 @@ package main
import "unsafe"
-var dummy [512<<20]byte; // give us a big address space
+var dummy [512<<20]byte // give us a big address space
func main() {
// the test only tests what we intend to test
// if dummy starts in the first 256 MB of memory.
@@ -18,7 +17,7 @@ func main() {
// at the address that might be accidentally
// dereferenced below.
if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
- panic("dummy too far out");
+ panic("dummy too far out")
}
// The problem here is that indexing into p[] with a large
@@ -28,6 +27,6 @@ func main() {
// To avoid needing a check on every slice beyond the
// usual len and cap, we require the slice operation
// to do the check.
- var p *[1<<30]byte = nil;
- var _ []byte = p[10:len(p)-10]; // should crash
+ var p *[1<<30]byte = nil
+ var _ []byte = p[10:len(p)-10] // should crash
}
diff --git a/test/nilptr/structfield.go b/test/nilptr/structfield.go
index 9f70ecc70..35196bb68 100644
--- a/test/nilptr/structfield.go
+++ b/test/nilptr/structfield.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -10,10 +9,10 @@ package main
import "unsafe"
-var dummy [512<<20]byte; // give us a big address space
+var dummy [512<<20]byte // give us a big address space
type T struct {
- x [256<<20] byte;
- i int;
+ x [256<<20] byte
+ i int
}
func main() {
@@ -23,13 +22,13 @@ func main() {
// at the address that might be accidentally
// dereferenced below.
if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
- panic("dummy too far out");
+ panic("dummy too far out")
}
// The problem here is that indexing into t with a large
// enough index can jump out of the unmapped section
// at the beginning of memory and into valid memory.
// We require the pointer dereference to check.
- var t *T;
- println(t.i); // should crash
+ var t *T
+ println(t.i) // should crash
}
diff --git a/test/nilptr/structfield1.go b/test/nilptr/structfield1.go
index 1a120890a..7c7abed1a 100644
--- a/test/nilptr/structfield1.go
+++ b/test/nilptr/structfield1.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -10,14 +9,14 @@ package main
import "unsafe"
-var dummy [512<<20]byte; // give us a big address space
+var dummy [512<<20]byte // give us a big address space
type T struct {
- x [256<<20] byte;
- i int;
+ x [256<<20] byte
+ i int
}
func f() *T {
- return nil;
+ return nil
}
func main() {
@@ -27,12 +26,12 @@ func main() {
// at the address that might be accidentally
// dereferenced below.
if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
- panic("dummy too far out");
+ panic("dummy too far out")
}
// The problem here is that indexing into t with a large
// enough index can jump out of the unmapped section
// at the beginning of memory and into valid memory.
// We require the pointer dereference to check.
- println(f().i); // should crash
+ println(f().i) // should crash
}
diff --git a/test/nilptr/structfield2.go b/test/nilptr/structfield2.go
index 25ea8f665..02a44f173 100644
--- a/test/nilptr/structfield2.go
+++ b/test/nilptr/structfield2.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -10,14 +9,14 @@ package main
import "unsafe"
-var dummy [512<<20]byte; // give us a big address space
+var dummy [512<<20]byte // give us a big address space
type T struct {
- x [256<<20] byte;
- i int;
+ x [256<<20] byte
+ i int
}
-var y *T;
-var x = &y;
+var y *T
+var x = &y
func main() {
// the test only tests what we intend to test
@@ -26,12 +25,12 @@ func main() {
// at the address that might be accidentally
// dereferenced below.
if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
- panic("dummy too far out");
+ panic("dummy too far out")
}
// The problem here is that indexing into t with a large
// enough index can jump out of the unmapped section
// at the beginning of memory and into valid memory.
// We require the pointer dereference to check.
- println((*x).i); // should crash
+ println((*x).i) // should crash
}
diff --git a/test/nilptr/structfieldaddr.go b/test/nilptr/structfieldaddr.go
index b5d370ca8..f3177bafb 100644
--- a/test/nilptr/structfieldaddr.go
+++ b/test/nilptr/structfieldaddr.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
// $G $D/$F.go && $L $F.$A &&
// ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
@@ -10,10 +9,10 @@ package main
import "unsafe"
-var dummy [512<<20]byte; // give us a big address space
+var dummy [512<<20]byte // give us a big address space
type T struct {
- x [256<<20] byte;
- i int;
+ x [256<<20] byte
+ i int
}
func main() {
@@ -23,13 +22,13 @@ func main() {
// at the address that might be accidentally
// dereferenced below.
if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
- panic("dummy too far out");
+ panic("dummy too far out")
}
// The problem here is that indexing into t with a large
// enough index can jump out of the unmapped section
// at the beginning of memory and into valid memory.
// We require the address calculation to check.
- var t *T;
- println(&t.i); // should crash
+ var t *T
+ println(&t.i) // should crash
}
diff --git a/test/nul1.go b/test/nul1.go
index 5e4596331..9cf51125b 100644
--- a/test/nul1.go
+++ b/test/nul1.go
@@ -1,4 +1,4 @@
-// [ $GOOS != nacl ] || exit 0 # NaCl runner elides NUL in output
+// [ "$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
@@ -24,7 +24,7 @@ func main() {
if len(s) != 2 || s[0] != 0xc2 || s[1] != 0xff ||
len(t) != 2 || t[0] != 0xd0 || t[1] != 0xfe ||
len(u) != 3 || u[0] != 0xab || u[1] != 0x00 || u[2] != 0xfc {
- println("BUG: non-UTF-8 string mangled");
+ println("BUG: non-UTF-8 string mangled")
os.Exit(2)
}
@@ -47,7 +47,7 @@ var yy = ` + "`in raw string \xff foo`" + ` // ERROR "UTF-8"
// in comment ` + "\xe2\x80\x01" + ` // ERROR "UTF-8"
-/* in other comment ` + "\xe0\x00\x00" + ` */ // ERROR "UTF-8"
+/* in other comment ` + "\xe0\x00\x00" + ` */ // ERROR "UTF-8|NUL"
/* in variable name */
var z` + "\xc1\x81" + ` int // ERROR "UTF-8"
diff --git a/test/parentype.go b/test/parentype.go
index d5729f820..1872cd0eb 100644
--- a/test/parentype.go
+++ b/test/parentype.go
@@ -9,11 +9,9 @@ package main
func f(interface{})
func g() {}
func main() {
- f(map[string]string{"a":"b","c":"d"});
- f([...]int{1,2,3});
- f(([...]int){1,2,3});
- f((map[string]string){"a":"b","c":"d"});
- f((map[string]func()){"a":g,"c":g});
- f(make(chan(<-chan int)));
- f(make(chan<-(chan int)));
+ f(map[string]string{"a":"b","c":"d"})
+ f([...]int{1,2,3})
+ f(map[string]func(){"a":g,"c":g})
+ f(make(chan(<-chan int)))
+ f(make(chan<-(chan int)))
}
diff --git a/test/peano.go b/test/peano.go
index 77a0d1272..f4c59d1e1 100644
--- a/test/peano.go
+++ b/test/peano.go
@@ -6,9 +6,7 @@
package main
-type Number struct {
- next *Number
-}
+type Number *Number
// -------------------------------------
@@ -26,13 +24,13 @@ func is_zero(x *Number) bool {
func add1(x *Number) *Number {
e := new(Number)
- e.next = x
+ *e = x
return e
}
func sub1(x *Number) *Number {
- return x.next
+ return *x
}
@@ -96,7 +94,7 @@ func check(x *Number, expected int) {
// -------------------------------------
// Test basic functionality
-func verify() {
+func init() {
check(zero(), 0)
check(add1(zero()), 1)
check(gen(10), 10)
@@ -121,10 +119,7 @@ func verify() {
// -------------------------------------
// Factorial
-
func main() {
-
- verify()
for i := 0; i <= 9; i++ {
print(i, "! = ", count(fact(gen(i))), "\n")
}
diff --git a/test/printbig.go b/test/printbig.go
index 5ec95b946..bbb707004 100644
--- a/test/printbig.go
+++ b/test/printbig.go
@@ -7,6 +7,6 @@
package main
func main() {
- print(-(1<<63), "\n");
+ print(-(1<<63), "\n")
print((1<<63)-1, "\n")
}
diff --git a/test/range.go b/test/range.go
index 9093d714b..91ccd6307 100644
--- a/test/range.go
+++ b/test/range.go
@@ -32,18 +32,59 @@ func testchan() {
}
}
-// test that range over array only evaluates
+// test that range over slice only evaluates
// the expression after "range" once.
var nmake = 0
-func makearray() []int {
+func makeslice() []int {
nmake++
return []int{1, 2, 3, 4, 5}
}
+func testslice() {
+ s := 0
+ nmake = 0
+ for _, v := range makeslice() {
+ s += v
+ }
+ if nmake != 1 {
+ println("range called makeslice", nmake, "times")
+ panic("fail")
+ }
+ if s != 15 {
+ println("wrong sum ranging over makeslice")
+ panic("fail")
+ }
+}
+
+func testslice1() {
+ s := 0
+ nmake = 0
+ for i := range makeslice() {
+ s += i
+ }
+ if nmake != 1 {
+ println("range called makeslice", nmake, "times")
+ panic("fail")
+ }
+ if s != 10 {
+ println("wrong sum ranging over makeslice")
+ panic("fail")
+ }
+}
+
+// test that range over array only evaluates
+// the expression after "range" once.
+
+func makearray() [5]int {
+ nmake++
+ return [5]int{1, 2, 3, 4, 5}
+}
+
func testarray() {
s := 0
+ nmake = 0
for _, v := range makearray() {
s += v
}
@@ -57,6 +98,151 @@ func testarray() {
}
}
+func testarray1() {
+ s := 0
+ nmake = 0
+ for i := range makearray() {
+ s += i
+ }
+ if nmake != 1 {
+ println("range called makearray", nmake, "times")
+ panic("fail")
+ }
+ if s != 10 {
+ println("wrong sum ranging over makearray")
+ panic("fail")
+ }
+}
+
+func makearrayptr() *[5]int {
+ nmake++
+ return &[5]int{1, 2, 3, 4, 5}
+}
+
+func testarrayptr() {
+ nmake = 0
+ x := len(makearrayptr())
+ if x != 5 || nmake != 1 {
+ println("len called makearrayptr", nmake, "times and got len", x)
+ panic("fail")
+ }
+ nmake = 0
+ x = cap(makearrayptr())
+ if x != 5 || nmake != 1 {
+ println("cap called makearrayptr", nmake, "times and got len", x)
+ panic("fail")
+ }
+ s := 0
+ nmake = 0
+ for _, v := range makearrayptr() {
+ s += v
+ }
+ if nmake != 1 {
+ println("range called makearrayptr", nmake, "times")
+ panic("fail")
+ }
+ if s != 15 {
+ println("wrong sum ranging over makearrayptr")
+ panic("fail")
+ }
+}
+
+func testarrayptr1() {
+ s := 0
+ nmake = 0
+ for i := range makearrayptr() {
+ s += i
+ }
+ if nmake != 1 {
+ println("range called makearrayptr", nmake, "times")
+ panic("fail")
+ }
+ if s != 10 {
+ println("wrong sum ranging over makearrayptr")
+ panic("fail")
+ }
+}
+
+// test that range over string only evaluates
+// the expression after "range" once.
+
+func makestring() string {
+ nmake++
+ return "abcd☺"
+}
+
+func teststring() {
+ s := 0
+ nmake = 0
+ for _, v := range makestring() {
+ s += v
+ }
+ if nmake != 1 {
+ println("range called makestring", nmake, "times")
+ panic("fail")
+ }
+ if s != 'a'+'b'+'c'+'d'+'☺' {
+ println("wrong sum ranging over makestring")
+ panic("fail")
+ }
+}
+
+func teststring1() {
+ s := 0
+ nmake = 0
+ for i := range makestring() {
+ s += i
+ }
+ if nmake != 1 {
+ println("range called makestring", nmake, "times")
+ panic("fail")
+ }
+ if s != 10 {
+ println("wrong sum ranging over makestring")
+ panic("fail")
+ }
+}
+
+// test that range over map only evaluates
+// the expression after "range" once.
+
+func makemap() map[int]int {
+ nmake++
+ return map[int]int{0:'a', 1:'b', 2:'c', 3:'d', 4:'☺'}
+}
+
+func testmap() {
+ s := 0
+ nmake = 0
+ for _, v := range makemap() {
+ s += v
+ }
+ if nmake != 1 {
+ println("range called makemap", nmake, "times")
+ panic("fail")
+ }
+ if s != 'a'+'b'+'c'+'d'+'☺' {
+ println("wrong sum ranging over makemap")
+ panic("fail")
+ }
+}
+
+func testmap1() {
+ s := 0
+ nmake = 0
+ for i := range makemap() {
+ s += i
+ }
+ if nmake != 1 {
+ println("range called makemap", nmake, "times")
+ panic("fail")
+ }
+ if s != 10 {
+ println("wrong sum ranging over makemap")
+ panic("fail")
+ }
+}
+
// test that range evaluates the index and value expressions
// exactly once per iteration.
@@ -98,5 +284,14 @@ func testcalls() {
func main() {
testchan()
testarray()
+ testarray1()
+ testarrayptr()
+ testarrayptr1()
+ testslice()
+ testslice1()
+ teststring()
+ teststring1()
+ testmap()
+ testmap1()
testcalls()
}
diff --git a/test/recover2.go b/test/recover2.go
index 496909f35..f33af4457 100644
--- a/test/recover2.go
+++ b/test/recover2.go
@@ -7,7 +7,6 @@
// Test of recover for run-time errors.
// TODO(rsc):
-// integer divide by zero?
// null pointer accesses
package main
@@ -15,7 +14,6 @@ package main
import (
"os"
"strings"
- "syscall"
)
var x = make([]byte, 10)
@@ -52,7 +50,9 @@ func test2() {
func test3() {
defer mustRecover("slice")
- println(x[11:9])
+ var lo = 11
+ var hi = 9
+ println(x[lo:hi])
}
func test4() {
@@ -81,10 +81,6 @@ func test6() {
}
func test7() {
- if syscall.ARCH == "arm" || syscall.OS == "nacl" {
- // ARM doesn't have integer divide trap yet
- return
- }
defer mustRecover("divide by zero")
var x, y int
println(x / y)
diff --git a/test/recover3.go b/test/recover3.go
index b982ec8fa..2aa1df616 100644
--- a/test/recover3.go
+++ b/test/recover3.go
@@ -1,4 +1,3 @@
-// [ $GOOS != nacl ] || exit 0 # NaCl cannot recover from signals
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2010 The Go Authors. All rights reserved.
@@ -10,7 +9,6 @@ package main
import (
"runtime"
"strings"
- "syscall"
)
var didbug bool
@@ -44,7 +42,7 @@ func check(name string, f func(), err string) {
return
}
}()
-
+
f()
}
@@ -55,11 +53,8 @@ func main() {
var q *[10000]int
var i int
- // not catching divide by zero on the arm. is that even possible?
- if syscall.ARCH != "arm" {
- check("int-div-zero", func() { println(1/x) }, "integer divide by zero")
- check("int64-div-zero", func() { println(1/x64) }, "integer divide by zero")
- }
+ check("int-div-zero", func() { println(1 / x) }, "integer divide by zero")
+ check("int64-div-zero", func() { println(1 / x64) }, "integer divide by zero")
check("nil-deref", func() { println(p[0]) }, "nil pointer dereference")
check("nil-deref-1", func() { println(p[1]) }, "nil pointer dereference")
@@ -69,11 +64,13 @@ func main() {
var sl []int
check("array-bounds", func() { println(p[i]) }, "index out of range")
check("slice-bounds", func() { println(sl[i]) }, "index out of range")
-
+
var inter interface{}
inter = 1
check("type-concrete", func() { println(inter.(string)) }, "int, not string")
check("type-interface", func() { println(inter.(m)) }, "missing method m")
}
-type m interface{ m() }
+type m interface {
+ m()
+}
diff --git a/test/run b/test/run
index b3f54f12f..28d0caa0f 100755
--- a/test/run
+++ b/test/run
@@ -3,7 +3,8 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-export E=""
+eval $(gomake --no-print-directory -f ../src/Make.inc go-env)
+
case X"$GOARCH" in
Xamd64)
export A=6
@@ -13,7 +14,7 @@ X386)
;;
Xarm)
export A=5
- export E=${GORUN:-qemu-arm -cpu cortex-a8}
+ export E="$GORUN"
;;
*)
echo 1>&2 run: unsupported '$GOARCH'
@@ -33,7 +34,7 @@ unset GREP_OPTIONS # in case user has a non-standard set
failed=0
-PATH=/bin:/usr/bin:/usr/local/bin:${GOBIN:-$HOME/bin}:`pwd`
+PATH=/bin:/usr/bin:/usr/local/bin:${GOBIN:-$GOROOT/bin}:`pwd`
RUNFILE=/tmp/gorun-$$-$USER
TMP1FILE=/tmp/gotest1-$$-$USER
@@ -48,26 +49,47 @@ ulimit -c 0
true >pass.out >times.out
+exclude=false # exclude nothing
+golden=golden.out
+
+filterout() {
+ grep '^'"$2"'$' $1 >/dev/null
+}
+
for dir in . ken chan interface nilptr syntax fixedbugs bugs
do
echo
echo '==' $dir'/'
for i in $(ls $dir/*.go 2>/dev/null)
- do
+ do (
+ if $exclude $i; then
+ exit 0 # continues for loop
+ fi
export F=$(basename $i .go)
export D=$dir
- sed '/^\/\//!q' $i | sed 's@//@@; $d' |sed 's|./\$A.out|$E &|' >$RUNFILE
+ sed '/^\/\//!q' $i | sed 's@//@@; $d' |sed 's|./\$A.out|$E &|g' >$RUNFILE
if ! { time -p bash -c "bash $RUNFILE >$TMP1FILE 2>&1" ; } 2>$TMP2FILE
then
echo
echo "===========" $i
cat $TMP1FILE
echo >&2 fail: $i
+ echo "# $i # fail" >>pass.out
elif test -s $TMP1FILE
then
echo
echo "===========" $i
cat $TMP1FILE
+ if grep -q '^BUG' $TMP1FILE
+ then
+ if [ $dir != bugs ]
+ then
+ echo >&2 bug: $i
+ fi
+ echo "# $i # fail, BUG" >>pass.out
+ else
+ echo $i >>pass.out
+ fi
elif [ $dir = "bugs" ]
then
echo $i succeeded with no output.
@@ -75,7 +97,7 @@ do
echo $i >>pass.out
fi
echo $(awk 'NR==1{print $2}' $TMP2FILE) $D/$F >>times.out
- done
+ ) done
done | # clean up some stack noise
egrep -v '^(r[0-9a-z]+|[cfg]s) +0x' |
sed '/tmp.*Bus error/s/.*Bus/Bus/; /tmp.*Trace.BPT/s/.*Trace/Trace/
@@ -87,12 +109,13 @@ done | # clean up some stack noise
/^Trace\/BPT trap/d
/RUNFILE/ s/line 1: *[0-9]*/line 1: PID/
/^\$RUNFILE: line 1: PID Trace\/breakpoint trap/d
+ /Fault in NaCl untrusted code/d
/Segmentation fault/d
/^qemu: uncaught target signal 11 (Segmentation fault) - exiting/d' > run.out
-rm -f $RUNFILE $TMP1FILE $TMP2FILE *.$A $A.out
+rm -f $RUNFILE $TMP1FILE $TMP2FILE *.$A *.a $A.out
diffmsg=""
-if ! diff run.out golden.out
+if ! diff $golden run.out
then
diffmsg="; test output differs"
failed=1
diff --git a/test/run-arm b/test/run-arm
deleted file mode 100755
index c7545ae0e..000000000
--- a/test/run-arm
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/bin/sh
-# 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.
-
-export E=""
-case X"$GOARCH" in
-Xamd64)
- export A=6
- ;;
-X386)
- export A=8
- ;;
-Xarm)
- export A=5
- export E="${GORUN:-qemu-arm -cpu cortex-a8}"
- ;;
-*)
- echo 1>&2 run: unsupported '$GOARCH'
- exit 1
-esac
-
-export G=${A}g
-export L=${A}l
-export GOTRACEBACK=0
-
-PATH=/bin:/usr/bin:/usr/local/bin:${GOBIN:-$HOME/bin}:`pwd`
-
-RUNFILE=/tmp/gorun-$$-$USER
-TMP1FILE=/tmp/gotest1-$$-$USER
-TMP2FILE=/tmp/gotest2-$$-$USER
-FAILEDFILE=/tmp/gotest3-$$-$USER
-
-# don't run the machine out of memory: limit individual processes to 4GB.
-# on thresher, 3GB suffices to run the tests; with 2GB, peano fails.
-ulimit -v 4000000
-
-# no core files please
-ulimit -c 0
-
-true >times.out
-
-# TODO(kaib): figure out why the GC makes things so utterly slow.
-export GOGC=off
-export GOTRACEBACK=0
-
-for i in $(cat arm-pass.txt | sed 's/#.*//')
-do
- export F=$(basename $i .go)
- dir=$(dirname $i)
- export D=$dir
- sed '/^\/\//!q' $i | sed 's@//@@; $d' |sed 's|./\$A.out|$E &|' >$RUNFILE
- if ! { time -p bash -c "bash $RUNFILE >$TMP1FILE 2>&1" ; } 2>$TMP2FILE
- then
- echo
- echo "===========" $i
- cat $TMP1FILE
- echo >&2 fail: $i
- touch $FAILEDFILE
- elif test -s $TMP1FILE
- then
- echo
- echo "===========" $i
- cat $TMP1FILE
- elif [ $dir = "bugs" ]
- then
- echo $i succeeded with no output.
- fi
- echo $(awk 'NR==1{print $2}' $TMP2FILE) $D/$F >>times.out
-done | # clean up some stack noise
- egrep -v '^(r[0-9a-z]+|[cfg]s) +0x' |
- sed '/tmp.*Bus error/s/.*Bus/Bus/; /tmp.*Trace.BPT/s/.*Trace/Trace/
- s!'$RUNFILE'!$RUNFILE!g
- s/ PC=0x[0-9a-f]*/ PC=xxx/
- s/^pc: 0x[0-9a-f]*/pc: xxx/
- /^Trace\/breakpoint trap/d
- /^Trace\/BPT trap/d
- s!'$GOROOT'!$GOROOT!g
- /Segmentation fault/d
- /RUNFILE/ s/line 1: *[0-9]*/line 1: PID/
- /^\$RUNFILE: line 1: PID Trace\/breakpoint trap/d
- /^qemu: uncaught target signal 11 (Segmentation fault) - exiting/d' > run.out
-
-failed=0
-rm -f $RUNFILE $TMP1FILE $TMP2FILE *.$A $A.out
-diffmsg=""
-if ! diff -b run.out golden-arm.out
-then
- diffmsg="; test output differs"
- failed=1
-fi
-
-notinbugs=$(sed '/== bugs/q' run.out | grep -c '^BUG')
-inbugs=$(sed '1,/== bugs/d' run.out | grep -c '^BUG')
-
-echo 2>&1 $inbugs known bugs';' $notinbugs unexpected bugs$diffmsg
-
-if [ "$failed" != "0" ]; then
- echo FAILED
-fi
-
-exit $failed
diff --git a/test/runtime.go b/test/runtime.go
index 256873a7a..4be1d055b 100644
--- a/test/runtime.go
+++ b/test/runtime.go
@@ -16,5 +16,5 @@ package main
import "runtime"
func main() {
- runtime.printbool(true); // ERROR "unexported"
+ runtime.printbool(true) // ERROR "unexported"
}
diff --git a/test/sieve.go b/test/sieve.go
index ec2ce446e..4fa111582 100644
--- a/test/sieve.go
+++ b/test/sieve.go
@@ -9,7 +9,7 @@ package main
// Send the sequence 2, 3, 4, ... to channel 'ch'.
func Generate(ch chan<- int) {
for i := 2; ; i++ {
- ch <- i // Send 'i' to channel 'ch'.
+ ch <- i // Send 'i' to channel 'ch'.
}
}
@@ -17,22 +17,22 @@ func Generate(ch chan<- int) {
// removing those divisible by 'prime'.
func Filter(in <-chan int, out chan<- int, prime int) {
for {
- i := <-in; // Receive value of new variable 'i' from 'in'.
- if i % prime != 0 {
- out <- i // Send 'i' to channel 'out'.
+ i := <-in // Receive value of new variable 'i' from 'in'.
+ if i%prime != 0 {
+ out <- i // Send 'i' to channel 'out'.
}
}
}
// The prime sieve: Daisy-chain Filter processes together.
func Sieve() {
- ch := make(chan int); // Create a new channel.
- go Generate(ch); // Start Generate() as a subprocess.
+ ch := make(chan int) // Create a new channel.
+ go Generate(ch) // Start Generate() as a subprocess.
for {
- prime := <-ch;
- print(prime, "\n");
- ch1 := make(chan int);
- go Filter(ch, ch1, prime);
+ prime := <-ch
+ print(prime, "\n")
+ ch1 := make(chan int)
+ go Filter(ch, ch1, prime)
ch = ch1
}
}
diff --git a/test/sigchld.go b/test/sigchld.go
index 3887e2d02..1fb2e21bd 100644
--- a/test/sigchld.go
+++ b/test/sigchld.go
@@ -1,4 +1,3 @@
-// if [ $GOOS == nacl ]; then echo survived SIGCHLD; exit 0; fi # NaCl has no signals.
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2009 The Go Authors. All rights reserved.
@@ -10,6 +9,6 @@ package main
import "syscall"
func main() {
- syscall.Syscall(syscall.SYS_KILL, uintptr(syscall.Getpid()), syscall.SIGCHLD, 0);
- println("survived SIGCHLD");
+ syscall.Kill(syscall.Getpid(), syscall.SIGCHLD)
+ println("survived SIGCHLD")
}
diff --git a/test/sinit.go b/test/sinit.go
index 730106675..2adb931e1 100644
--- a/test/sinit.go
+++ b/test/sinit.go
@@ -9,10 +9,10 @@ package p
// Should be no init func in the assembly.
// All these initializations should be done at link time.
-type S struct{ a,b,c int };
-type SS struct{ aa,bb,cc S };
-type SA struct{ a,b,c [3]int };
-type SC struct{ a,b,c []int };
+type S struct{ a,b,c int }
+type SS struct{ aa,bb,cc S }
+type SA struct{ a,b,c [3]int }
+type SC struct{ a,b,c []int }
var (
zero = 2
diff --git a/test/solitaire.go b/test/solitaire.go
new file mode 100644
index 000000000..c789bf24a
--- /dev/null
+++ b/test/solitaire.go
@@ -0,0 +1,119 @@
+// $G $F.go && $L $F.$A # don't run it - produces too much output
+
+// 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.
+
+// This program solves the (English) peg solitaire board game.
+// See also: http://en.wikipedia.org/wiki/Peg_solitaire
+
+package main
+
+const N = 11 + 1 // length of a board row (+1 for newline)
+
+// The board must be surrounded by 2 illegal fields in each direction
+// so that move() doesn't need to check the board boundaries. Periods
+// represent illegal fields, ● are pegs, and ○ are holes.
+var board = []int(
+ `...........
+...........
+....●●●....
+....●●●....
+..●●●●●●●..
+..●●●○●●●..
+..●●●●●●●..
+....●●●....
+....●●●....
+...........
+...........
+`)
+
+
+// center is the position of the center hole if there is a single one;
+// otherwise it is -1.
+var center int
+
+func init() {
+ n := 0
+ for pos, field := range board {
+ if field == '○' {
+ center = pos
+ n++
+ }
+ }
+ if n != 1 {
+ center = -1 // no single hole
+ }
+}
+
+
+var moves int // number of times move is called
+
+// move tests if there is a peg at position pos that can jump over another peg
+// in direction dir. If the move is valid, it is executed and move returns true.
+// Otherwise, move returns false.
+func move(pos, dir int) bool {
+ moves++
+ if board[pos] == '●' && board[pos+dir] == '●' && board[pos+2*dir] == '○' {
+ board[pos] = '○'
+ board[pos+dir] = '○'
+ board[pos+2*dir] = '●'
+ return true
+ }
+ return false
+}
+
+
+// unmove reverts a previously executed valid move.
+func unmove(pos, dir int) {
+ board[pos] = '●'
+ board[pos+dir] = '●'
+ board[pos+2*dir] = '○'
+}
+
+
+// solve tries to find a sequence of moves such that there is only one peg left
+// at the end; if center is >= 0, that last peg must be in the center position.
+// If a solution is found, solve prints the board after each move in a backward
+// fashion (i.e., the last board position is printed first, all the way back to
+// the starting board position).
+func solve() bool {
+ var last, n int
+ for pos, field := range board {
+ // try each board position
+ if field == '●' {
+ // found a peg
+ for _, dir := range [...]int{-1, -N, +1, +N} {
+ // try each direction
+ if move(pos, dir) {
+ // a valid move was found and executed,
+ // see if this new board has a solution
+ if solve() {
+ unmove(pos, dir)
+ println(string(board))
+ return true
+ }
+ unmove(pos, dir)
+ }
+ }
+ last = pos
+ n++
+ }
+ }
+ // tried each possible move
+ if n == 1 && (center < 0 || last == center) {
+ // there's only one peg left
+ println(string(board))
+ return true
+ }
+ // no solution found for this board
+ return false
+}
+
+
+func main() {
+ if !solve() {
+ println("no solution found")
+ }
+ println(moves, "moves tried")
+}
diff --git a/test/string_lit.go b/test/string_lit.go
index 88b5d251f..4358dd8e8 100644
--- a/test/string_lit.go
+++ b/test/string_lit.go
@@ -12,15 +12,15 @@ var ecode int
func assert(a, b, c string) {
if a != b {
- ecode = 1;
- print("FAIL: ", c, ": ", a, "!=", b, "\n");
- var max int = len(a);
+ ecode = 1
+ print("FAIL: ", c, ": ", a, "!=", b, "\n")
+ var max int = len(a)
if len(b) > max {
max = len(b)
}
for i := 0; i < max; i++ {
- ac := 0;
- bc := 0;
+ ac := 0
+ bc := 0
if i < len(a) {
ac = int(a[i])
}
@@ -48,7 +48,7 @@ var (
)
func main() {
- ecode = 0;
+ ecode = 0
s :=
"" +
" " +
@@ -67,38 +67,38 @@ func main() {
`本` +
`\a\b\f\n\r\t\v\\\'` +
`\000\123\x00\xca\xFE\u0123\ubabe\U0000babe` +
- `\x\u\U\`;
+ `\x\u\U\`
- assert("", ``, "empty");
- assert(" ", " ", "blank");
- assert("\x61", "a", "lowercase a");
- assert("\x61", `a`, "lowercase a (backquote)");
- assert("\u00e4", "ä", "a umlaut");
- assert("\u00e4", `ä`, "a umlaut (backquote)");
- assert("\u672c", "本", "nihon");
- assert("\u672c", `本`, "nihon (backquote)");
+ assert("", ``, "empty")
+ assert(" ", " ", "blank")
+ assert("\x61", "a", "lowercase a")
+ assert("\x61", `a`, "lowercase a (backquote)")
+ assert("\u00e4", "ä", "a umlaut")
+ assert("\u00e4", `ä`, "a umlaut (backquote)")
+ assert("\u672c", "本", "nihon")
+ assert("\u672c", `本`, "nihon (backquote)")
assert("\x07\x08\x0c\x0a\x0d\x09\x0b\x5c\x22",
"\a\b\f\n\r\t\v\\\"",
- "backslashes");
+ "backslashes")
assert("\\a\\b\\f\\n\\r\\t\\v\\\\\\\"",
`\a\b\f\n\r\t\v\\\"`,
- "backslashes (backquote)");
+ "backslashes (backquote)")
assert("\x00\x53\000\xca\376S몾몾",
"\000\123\x00\312\xFE\u0053\ubabe\U0000babe",
- "backslashes 2");
+ "backslashes 2")
assert("\\000\\123\\x00\\312\\xFE\\u0123\\ubabe\\U0000babe",
`\000\123\x00\312\xFE\u0123\ubabe\U0000babe`,
- "backslashes 2 (backquote)");
- assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)");
+ "backslashes 2 (backquote)")
+ assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)")
// test large runes. perhaps not the most logical place for this test.
- var r int32;
+ var r int32
r = 0x10ffff; // largest rune value
- s = string(r);
- assert(s, "\xf4\x8f\xbf\xbf", "largest rune");
- r = 0x10ffff + 1;
- s = string(r);
- assert(s, "\xef\xbf\xbd", "too-large rune");
+ s = string(r)
+ assert(s, "\xf4\x8f\xbf\xbf", "largest rune")
+ r = 0x10ffff + 1
+ s = string(r)
+ assert(s, "\xef\xbf\xbd", "too-large rune")
assert(string(gr1), gx1, "global ->[]int")
assert(string(gr2), gx2fix, "global invalid ->[]int")
@@ -116,5 +116,5 @@ func main() {
assert(string(b1), gx1, "->[]byte")
assert(string(b2), gx2, "invalid ->[]byte")
- os.Exit(ecode);
+ os.Exit(ecode)
}
diff --git a/test/stringrange.go b/test/stringrange.go
index 9215b95fa..d5ada2628 100644
--- a/test/stringrange.go
+++ b/test/stringrange.go
@@ -7,55 +7,55 @@
package main
import (
- "fmt";
- "os";
- "utf8";
+ "fmt"
+ "os"
+ "utf8"
)
func main() {
- s := "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe\U0010FFFFx";
- expect := []int{ 0, 0123, 0, 0xFFFD, 0xFFFD, 0x123, 0xbabe, 0xbabe, 0x10FFFF, 'x' };
- offset := 0;
- var i, c int;
- ok := true;
- cnum := 0;
+ s := "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe\U0010FFFFx"
+ expect := []int{ 0, 0123, 0, 0xFFFD, 0xFFFD, 0x123, 0xbabe, 0xbabe, 0x10FFFF, 'x' }
+ offset := 0
+ var i, c int
+ ok := true
+ cnum := 0
for i, c = range s {
- rune, size := utf8.DecodeRuneInString(s[i:len(s)]); // check it another way
+ rune, size := utf8.DecodeRuneInString(s[i:len(s)]) // check it another way
if i != offset {
- fmt.Printf("unexpected offset %d not %d\n", i, offset);
- ok = false;
+ fmt.Printf("unexpected offset %d not %d\n", i, offset)
+ ok = false
}
if rune != expect[cnum] {
- fmt.Printf("unexpected rune %d from DecodeRuneInString: %x not %x\n", i, rune, expect[cnum]);
- ok = false;
+ fmt.Printf("unexpected rune %d from DecodeRuneInString: %x not %x\n", i, rune, expect[cnum])
+ ok = false
}
if c != expect[cnum] {
- fmt.Printf("unexpected rune %d from range: %x not %x\n", i, rune, expect[cnum]);
- ok = false;
+ fmt.Printf("unexpected rune %d from range: %x not %x\n", i, rune, expect[cnum])
+ ok = false
}
- offset += size;
- cnum++;
+ offset += size
+ cnum++
}
if i != len(s)-1 {
- fmt.Println("after loop i is", i, "not", len(s)-1);
- ok = false;
+ fmt.Println("after loop i is", i, "not", len(s)-1)
+ ok = false
}
- i = 12345;
- c = 23456;
+ i = 12345
+ c = 23456
for i, c = range "" {
}
if i != 12345 {
- fmt.Println("range empty string assigned to index:", i);
- ok = false;
+ fmt.Println("range empty string assigned to index:", i)
+ ok = false
}
if c != 23456 {
- fmt.Println("range empty string assigned to value:", c);
- ok = false;
+ fmt.Println("range empty string assigned to value:", c)
+ ok = false
}
if !ok {
- fmt.Println("BUG: stringrange");
+ fmt.Println("BUG: stringrange")
os.Exit(1)
}
}
diff --git a/test/switch.go b/test/switch.go
index 835c90081..0c253d6e2 100644
--- a/test/switch.go
+++ b/test/switch.go
@@ -8,59 +8,59 @@ package main
func assert(cond bool, msg string) {
if !cond {
- print("assertion fail: ", msg, "\n");
- panic(1);
+ print("assertion fail: ", msg, "\n")
+ panic(1)
}
}
func main() {
- i5 := 5;
- i7 := 7;
- hello := "hello";
+ i5 := 5
+ i7 := 7
+ hello := "hello"
switch true {
- case i5 < 5: assert(false, "<");
- case i5 == 5: assert(true, "!");
- case i5 > 5: assert(false, ">");
+ case i5 < 5: assert(false, "<")
+ case i5 == 5: assert(true, "!")
+ case i5 > 5: assert(false, ">")
}
switch {
- case i5 < 5: assert(false, "<");
- case i5 == 5: assert(true, "!");
- case i5 > 5: assert(false, ">");
+ case i5 < 5: assert(false, "<")
+ case i5 == 5: assert(true, "!")
+ case i5 > 5: assert(false, ">")
}
switch x := 5; true {
- case i5 < x: assert(false, "<");
- case i5 == x: assert(true, "!");
- case i5 > x: assert(false, ">");
+ case i5 < x: assert(false, "<")
+ case i5 == x: assert(true, "!")
+ case i5 > x: assert(false, ">")
}
switch x := 5; true {
- case i5 < x: assert(false, "<");
- case i5 == x: assert(true, "!");
- case i5 > x: assert(false, ">");
+ case i5 < x: assert(false, "<")
+ case i5 == x: assert(true, "!")
+ case i5 > x: assert(false, ">")
}
switch i5 {
- case 0: assert(false, "0");
- case 1: assert(false, "1");
- case 2: assert(false, "2");
- case 3: assert(false, "3");
- case 4: assert(false, "4");
- case 5: assert(true, "5");
- case 6: assert(false, "6");
- case 7: assert(false, "7");
- case 8: assert(false, "8");
- case 9: assert(false, "9");
- default: assert(false, "default");
+ case 0: assert(false, "0")
+ case 1: assert(false, "1")
+ case 2: assert(false, "2")
+ case 3: assert(false, "3")
+ case 4: assert(false, "4")
+ case 5: assert(true, "5")
+ case 6: assert(false, "6")
+ case 7: assert(false, "7")
+ case 8: assert(false, "8")
+ case 9: assert(false, "9")
+ default: assert(false, "default")
}
switch i5 {
- case 0,1,2,3,4: assert(false, "4");
- case 5: assert(true, "5");
- case 6,7,8,9: assert(false, "9");
- default: assert(false, "default");
+ case 0,1,2,3,4: assert(false, "4")
+ case 5: assert(true, "5")
+ case 6,7,8,9: assert(false, "9")
+ default: assert(false, "default")
}
switch i5 {
@@ -68,72 +68,72 @@ func main() {
case 1:
case 2:
case 3:
- case 4: assert(false, "4");
- case 5: assert(true, "5");
+ case 4: assert(false, "4")
+ case 5: assert(true, "5")
case 6:
case 7:
case 8:
case 9:
- default: assert(i5 == 5, "good");
+ default: assert(i5 == 5, "good")
}
switch i5 {
- case 0: dummy := 0; _ = dummy; fallthrough;
- case 1: dummy := 0; _ = dummy; fallthrough;
- case 2: dummy := 0; _ = dummy; fallthrough;
- case 3: dummy := 0; _ = dummy; fallthrough;
- case 4: dummy := 0; _ = dummy; assert(false, "4");
- case 5: dummy := 0; _ = dummy; fallthrough;
- case 6: dummy := 0; _ = dummy; fallthrough;
- case 7: dummy := 0; _ = dummy; fallthrough;
- case 8: dummy := 0; _ = dummy; fallthrough;
- case 9: dummy := 0; _ = dummy; fallthrough;
- default: dummy := 0; _ = dummy; assert(i5 == 5, "good");
+ case 0: dummy := 0; _ = dummy; fallthrough
+ case 1: dummy := 0; _ = dummy; fallthrough
+ case 2: dummy := 0; _ = dummy; fallthrough
+ case 3: dummy := 0; _ = dummy; fallthrough
+ case 4: dummy := 0; _ = dummy; assert(false, "4")
+ case 5: dummy := 0; _ = dummy; fallthrough
+ case 6: dummy := 0; _ = dummy; fallthrough
+ case 7: dummy := 0; _ = dummy; fallthrough
+ case 8: dummy := 0; _ = dummy; fallthrough
+ case 9: dummy := 0; _ = dummy; fallthrough
+ default: dummy := 0; _ = dummy; assert(i5 == 5, "good")
}
- fired := false;
+ fired := false
switch i5 {
case 0: dummy := 0; _ = dummy; fallthrough; // tests scoping of cases
- case 1: dummy := 0; _ = dummy; fallthrough;
- case 2: dummy := 0; _ = dummy; fallthrough;
- case 3: dummy := 0; _ = dummy; fallthrough;
- case 4: dummy := 0; _ = dummy; assert(false, "4");
- case 5: dummy := 0; _ = dummy; fallthrough;
- case 6: dummy := 0; _ = dummy; fallthrough;
- case 7: dummy := 0; _ = dummy; fallthrough;
- case 8: dummy := 0; _ = dummy; fallthrough;
- case 9: dummy := 0; _ = dummy; fallthrough;
- default: dummy := 0; _ = dummy; fired = !fired; assert(i5 == 5, "good");
+ case 1: dummy := 0; _ = dummy; fallthrough
+ case 2: dummy := 0; _ = dummy; fallthrough
+ case 3: dummy := 0; _ = dummy; fallthrough
+ case 4: dummy := 0; _ = dummy; assert(false, "4")
+ case 5: dummy := 0; _ = dummy; fallthrough
+ case 6: dummy := 0; _ = dummy; fallthrough
+ case 7: dummy := 0; _ = dummy; fallthrough
+ case 8: dummy := 0; _ = dummy; fallthrough
+ case 9: dummy := 0; _ = dummy; fallthrough
+ default: dummy := 0; _ = dummy; fired = !fired; assert(i5 == 5, "good")
}
- assert(fired, "fired");
+ assert(fired, "fired")
- count := 0;
+ count := 0
switch i5 {
- case 0: count = count + 1; fallthrough;
- case 1: count = count + 1; fallthrough;
- case 2: count = count + 1; fallthrough;
- case 3: count = count + 1; fallthrough;
- case 4: count = count + 1; assert(false, "4");
- case 5: count = count + 1; fallthrough;
- case 6: count = count + 1; fallthrough;
- case 7: count = count + 1; fallthrough;
- case 8: count = count + 1; fallthrough;
- case 9: count = count + 1; fallthrough;
- default: assert(i5 == count, "good");
+ case 0: count = count + 1; fallthrough
+ case 1: count = count + 1; fallthrough
+ case 2: count = count + 1; fallthrough
+ case 3: count = count + 1; fallthrough
+ case 4: count = count + 1; assert(false, "4")
+ case 5: count = count + 1; fallthrough
+ case 6: count = count + 1; fallthrough
+ case 7: count = count + 1; fallthrough
+ case 8: count = count + 1; fallthrough
+ case 9: count = count + 1; fallthrough
+ default: assert(i5 == count, "good")
}
- assert(fired, "fired");
+ assert(fired, "fired")
switch hello {
- case "wowie": assert(false, "wowie");
- case "hello": assert(true, "hello");
- case "jumpn": assert(false, "jumpn");
- default: assert(false, "default");
+ case "wowie": assert(false, "wowie")
+ case "hello": assert(true, "hello")
+ case "jumpn": assert(false, "jumpn")
+ default: assert(false, "default")
}
- fired = false;
+ fired = false
switch i := i5 + 2; i {
- case i7: fired = true;
- default: assert(false, "fail");
+ case i7: fired = true
+ default: assert(false, "fail")
}
- assert(fired, "var");
+ assert(fired, "var")
}
diff --git a/test/switch1.go b/test/switch1.go
index 9e61cc658..5bd9d7c5d 100644
--- a/test/switch1.go
+++ b/test/switch1.go
@@ -9,12 +9,12 @@ package main
import "os"
func main() {
- i := 0;
+ i := 0
switch x := 5; {
case i < x:
- os.Exit(0);
+ os.Exit(0)
case i == x:
case i > x:
- os.Exit(1);
+ os.Exit(1)
}
}
diff --git a/test/syntax/chan.go b/test/syntax/chan.go
new file mode 100644
index 000000000..48beb1e70
--- /dev/null
+++ b/test/syntax/chan.go
@@ -0,0 +1,17 @@
+// errchk $G -e $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.
+
+package main
+
+type xyz struct {
+ ch chan
+} // ERROR "unexpected } in channel type"
+
+func Foo(y chan) { // ERROR "unexpected \) in channel type"
+}
+
+func Bar(x chan, y int) { // ERROR "unexpected comma in channel type"
+}
diff --git a/test/syntax/topexpr.go b/test/syntax/topexpr.go
index 83de49075..93d86fbe9 100644
--- a/test/syntax/topexpr.go
+++ b/test/syntax/topexpr.go
@@ -6,15 +6,15 @@
package main
-fmt.Printf("hello") // ERROR "non-declaration statement outside function body"
+fmt.Printf("hello") // ERROR "non-declaration statement outside function body|expected declaration"
func main() {
}
-x++ // ERROR "non-declaration statement outside function body"
+x++ // ERROR "non-declaration statement outside function body|expected declaration"
func init() {
}
-x,y := 1, 2 // ERROR "non-declaration statement outside function body"
+x,y := 1, 2 // ERROR "non-declaration statement outside function body|expected declaration"
diff --git a/test/syntax/vareq.go b/test/syntax/vareq.go
index 9be03c1d3..8525be8cf 100644
--- a/test/syntax/vareq.go
+++ b/test/syntax/vareq.go
@@ -7,4 +7,4 @@
package main
func main() {
- var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement"
+ var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement|expected ';' or '}' or newline"
diff --git a/test/syntax/vareq1.go b/test/syntax/vareq1.go
index 2d35b3ea0..9d70bea39 100644
--- a/test/syntax/vareq1.go
+++ b/test/syntax/vareq1.go
@@ -6,5 +6,5 @@
package main
-var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement"
+var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement|expected ';' or newline after top level declaration"
diff --git a/test/test0.go b/test/test0.go
index f42b12b3c..dd2033a98 100644
--- a/test/test0.go
+++ b/test/test0.go
@@ -10,34 +10,34 @@ const
a_const = 0
const (
- pi = /* the usual */ 3.14159265358979323;
- e = 2.718281828;
- mask1 int = 1 << iota;
- mask2 = 1 << iota;
- mask3 = 1 << iota;
- mask4 = 1 << iota;
+ pi = /* the usual */ 3.14159265358979323
+ e = 2.718281828
+ mask1 int = 1 << iota
+ mask2 = 1 << iota
+ mask3 = 1 << iota
+ mask4 = 1 << iota
)
type (
- Empty interface {};
+ Empty interface {}
Point struct {
- x, y int;
- };
+ x, y int
+ }
Point2 Point
)
func (p *Point) Initialize(x, y int) *Point {
- p.x, p.y = x, y;
- return p;
+ p.x, p.y = x, y
+ return p
}
func (p *Point) Distance() int {
- return p.x * p.x + p.y * p.y;
+ return p.x * p.x + p.y * p.y
}
var (
- x1 int;
- x2 int;
+ x1 int
+ x2 int
u, v, w float
)
@@ -45,40 +45,40 @@ func foo() {}
func min(x, y int) int {
if x < y { return x; }
- return y;
+ return y
}
func swap(x, y int) (u, v int) {
- u = y;
- v = x;
- return;
+ u = y
+ v = x
+ return
}
func control_structs() {
- var p *Point = new(Point).Initialize(2, 3);
- i := p.Distance();
- var f float = 0.3;
- _ = f;
+ var p *Point = new(Point).Initialize(2, 3)
+ i := p.Distance()
+ var f float = 0.3
+ _ = f
+ for {}
for {}
- for {};
for j := 0; j < i; j++ {
if i == 0 {
- } else i = 0;
- var x float;
- _ = x;
+ } else i = 0
+ var x float
+ _ = x
}
foo: // a label
- var j int;
+ var j int
switch y := 0; true {
case i < y:
- fallthrough;
+ fallthrough
case i < j:
case i == 0, i == 1, i == j:
- i++; i++;
- goto foo;
+ i++; i++
+ goto foo
default:
- i = -+-+i;
- break;
+ i = -+-+i
+ break
}
}
diff --git a/test/turing.go b/test/turing.go
index 462bb9168..0af39de8b 100644
--- a/test/turing.go
+++ b/test/turing.go
@@ -8,48 +8,45 @@ package main
// brainfuck
+var p, pc int
+var a [30000]byte
+const prog = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.!"
+
+func scan(dir int) {
+ for nest := dir; dir*nest > 0; pc += dir {
+ switch prog[pc+dir] {
+ case ']':
+ nest--
+ case '[':
+ nest++
+ }
+ }
+}
+
func main() {
- var a [30000]byte;
- prog := "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.!";
- p := 0;
- pc := 0;
for {
switch prog[pc] {
case '>':
- p++;
+ p++
case '<':
- p--;
+ p--
case '+':
- a[p]++;
+ a[p]++
case '-':
- a[p]--;
+ a[p]--
case '.':
- print(string(a[p]));
+ print(string(a[p]))
case '[':
if a[p] == 0 {
- for nest := 1; nest > 0; pc++ {
- switch prog[pc+1] {
- case ']':
- nest--;
- case '[':
- nest++;
- }
- }
+ scan(1)
}
case ']':
if a[p] != 0 {
- for nest := -1; nest < 0; pc-- {
- switch prog[pc-1] {
- case ']':
- nest--;
- case '[':
- nest++;
- }
- }
+ scan(-1)
}
default:
- return;
+ return
}
- pc++;
+ pc++
}
}
diff --git a/test/typeswitch.go b/test/typeswitch.go
index 0a421ae96..9e6d10ea8 100644
--- a/test/typeswitch.go
+++ b/test/typeswitch.go
@@ -9,22 +9,22 @@ package main
import "os"
const (
- Bool = iota;
- Int;
- Float;
- String;
- Struct;
- Chan;
- Array;
- Map;
- Func;
- Last;
+ Bool = iota
+ Int
+ Float
+ String
+ Struct
+ Chan
+ Array
+ Map
+ Func
+ Last
)
type S struct { a int }
var s S = S{1234}
-var c = make(chan int);
+var c = make(chan int)
var a = []int{0,1,2,3}
@@ -32,81 +32,81 @@ var m = make(map[string]int)
func assert(b bool, s string) {
if !b {
- println(s);
- os.Exit(1);
+ println(s)
+ os.Exit(1)
}
}
func f(i int) interface{} {
switch i {
case Bool:
- return true;
+ return true
case Int:
- return 7;
+ return 7
case Float:
- return 7.4;
+ return 7.4
case String:
- return "hello";
+ return "hello"
case Struct:
- return s;
+ return s
case Chan:
- return c;
+ return c
case Array:
- return a;
+ return a
case Map:
- return m;
+ return m
case Func:
- return f;
+ return f
}
- panic("bad type number");
+ panic("bad type number")
}
func main() {
for i := Bool; i < Last; i++ {
switch x := f(i).(type) {
case bool:
- assert(x == true && i == Bool, "bool");
+ assert(x == true && i == Bool, "bool")
case int:
- assert(x == 7 && i == Int, "int");
+ assert(x == 7 && i == Int, "int")
case float:
- assert(x == 7.4 && i == Float, "float");
+ assert(x == 7.4 && i == Float, "float")
case string:
- assert(x == "hello"&& i == String, "string");
+ assert(x == "hello"&& i == String, "string")
case S:
- assert(x.a == 1234 && i == Struct, "struct");
+ assert(x.a == 1234 && i == Struct, "struct")
case chan int:
- assert(x == c && i == Chan, "chan");
+ assert(x == c && i == Chan, "chan")
case []int:
- assert(x[3] == 3 && i == Array, "array");
+ assert(x[3] == 3 && i == Array, "array")
case map[string]int:
- assert(x == m && i == Map, "map");
+ assert(x == m && i == Map, "map")
case func(i int) interface{}:
- assert(x == f && i == Func, "fun");
+ assert(x == f && i == Func, "fun")
default:
- assert(false, "unknown");
+ assert(false, "unknown")
}
}
// boolean switch (has had bugs in past; worth writing down)
switch {
case true:
- assert(true, "switch 2 bool");
+ assert(true, "switch 2 bool")
default:
- assert(false, "switch 2 unknown");
+ assert(false, "switch 2 unknown")
}
switch true {
case true:
- assert(true, "switch 3 bool");
+ assert(true, "switch 3 bool")
default:
- assert(false, "switch 3 unknown");
+ assert(false, "switch 3 unknown")
}
switch false {
case false:
- assert(true, "switch 4 bool");
+ assert(true, "switch 4 bool")
default:
- assert(false, "switch 4 unknown");
+ assert(false, "switch 4 unknown")
}
}
diff --git a/test/undef.go b/test/undef.go
index 70785675a..7ef07882a 100644
--- a/test/undef.go
+++ b/test/undef.go
@@ -9,9 +9,9 @@
package main
var (
- _ = x // ERROR "undefined: x"
- _ = x // ERROR "undefined: x"
- _ = x // ERROR "undefined: x"
+ _ = x // ERROR "undefined.*x"
+ _ = x // ERROR "undefined.*x"
+ _ = x // ERROR "undefined.*x"
)
type T struct {
@@ -19,7 +19,7 @@ type T struct {
}
func foo() *T { return &T{y: 99} }
-func bar() int { return y } // ERROR "undefined: y"
+func bar() int { return y } // ERROR "undefined.*y"
type T1 struct {
y1 int
@@ -39,6 +39,6 @@ func f1(val interface{}) {
func f2(val interface{}) {
switch val.(type) {
default:
- println(v) // ERROR "undefined: v"
+ println(v) // ERROR "undefined.*v"
}
}
diff --git a/test/utf.go b/test/utf.go
index 59b0ffaa9..a93fc2934 100644
--- a/test/utf.go
+++ b/test/utf.go
@@ -9,46 +9,46 @@ package main
import "utf8"
func main() {
- var chars [6] int;
- chars[0] = 'a';
- chars[1] = 'b';
- chars[2] = 'c';
- chars[3] = '\u65e5';
- chars[4] = '\u672c';
- chars[5] = '\u8a9e';
- s := "";
+ var chars [6] int
+ chars[0] = 'a'
+ chars[1] = 'b'
+ chars[2] = 'c'
+ chars[3] = '\u65e5'
+ chars[4] = '\u672c'
+ chars[5] = '\u8a9e'
+ s := ""
for i := 0; i < 6; i++ {
- s += string(chars[i]);
+ s += string(chars[i])
}
- var l = len(s);
+ var l = len(s)
for w, i, j := 0,0,0; i < l; i += w {
- var r int;
- r, w = utf8.DecodeRuneInString(s[i:len(s)]);
+ var r int
+ r, w = utf8.DecodeRuneInString(s[i:len(s)])
if w == 0 { panic("zero width in string") }
if r != chars[j] { panic("wrong value from string") }
- j++;
+ j++
}
// encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e
- const L = 12;
+ const L = 12
if L != l { panic("wrong length constructing array") }
- a := make([]byte, L);
- a[0] = 'a';
- a[1] = 'b';
- a[2] = 'c';
- a[3] = 0xe6;
- a[4] = 0x97;
- a[5] = 0xa5;
- a[6] = 0xe6;
- a[7] = 0x9c;
- a[8] = 0xac;
- a[9] = 0xe8;
- a[10] = 0xaa;
- a[11] = 0x9e;
+ a := make([]byte, L)
+ a[0] = 'a'
+ a[1] = 'b'
+ a[2] = 'c'
+ a[3] = 0xe6
+ a[4] = 0x97
+ a[5] = 0xa5
+ a[6] = 0xe6
+ a[7] = 0x9c
+ a[8] = 0xac
+ a[9] = 0xe8
+ a[10] = 0xaa
+ a[11] = 0x9e
for w, i, j := 0,0,0; i < L; i += w {
- var r int;
- r, w = utf8.DecodeRune(a[i:L]);
+ var r int
+ r, w = utf8.DecodeRune(a[i:L])
if w == 0 { panic("zero width in bytes") }
if r != chars[j] { panic("wrong value from bytes") }
- j++;
+ j++
}
}
diff --git a/test/varerr.go b/test/varerr.go
index 32f33ecc7..ddd718f5b 100644
--- a/test/varerr.go
+++ b/test/varerr.go
@@ -7,8 +7,8 @@
package main
func main() {
- _ = asdf // ERROR "undefined: asdf"
+ _ = asdf // ERROR "undefined.*asdf"
- new = 1 // ERROR "use of builtin new not in function call"
+ new = 1 // ERROR "use of builtin new not in function call|invalid left hand side"
}
diff --git a/test/zerodivide.go b/test/zerodivide.go
index 9d35b392b..cd4f52215 100644
--- a/test/zerodivide.go
+++ b/test/zerodivide.go
@@ -10,7 +10,6 @@ import (
"fmt"
"math"
"strings"
- "syscall"
)
type Error interface {
@@ -46,6 +45,30 @@ var (
c128, d128, e128 complex128 = 0+0i, 0+0i, 1+1i
)
+// Fool gccgo into thinking that these variables can change.
+func NotCalled() {
+ i++; j++; k++
+ i8++; j8++; k8++
+ i16++; j16++; k16++
+ i32++; j32++; k32++
+ i64++; j64++; k64++
+
+ u++; v++; w++
+ u8++; v8++; w8++
+ u16++; v16++; w16++
+ u32++; v32++; w32++
+ u64++; v64++; w64++
+ up++; vp++; wp++
+
+ f += 1; g += 1; h += 1
+ f32 += 1; g32 += 1; h32 += 1
+ f64 += 1; g64 += 1; h64 += 1
+
+ c += 1+1i; d += 1+1i; e += 1+1i
+ c64 += 1+1i; d64 += 1+1i; e64 += 1+1i
+ c128 += 1+1i; d128 += 1+1i; e128 += 1+1i
+}
+
var tmp interface{}
// We could assign to _ but the compiler optimizes it too easily.
@@ -137,8 +160,9 @@ func alike(a, b float64) bool {
}
func main() {
+ bad := false
for _, t := range errorTests {
- if t.err != "" && syscall.OS == "nacl" {
+ if t.err != "" {
continue
}
err := error(t.fn)
@@ -146,11 +170,23 @@ func main() {
case t.err == "" && err == "":
// fine
case t.err != "" && err == "":
+ if !bad {
+ bad = true
+ fmt.Printf("BUG\n")
+ }
fmt.Printf("%s: expected %q; got no error\n", t.name, t.err)
case t.err == "" && err != "":
+ if !bad {
+ bad = true
+ fmt.Printf("BUG\n")
+ }
fmt.Printf("%s: expected no error; got %q\n", t.name, err)
case t.err != "" && err != "":
if strings.Index(err, t.err) < 0 {
+ if !bad {
+ bad = true
+ fmt.Printf("BUG\n")
+ }
fmt.Printf("%s: expected %q; got %q\n", t.name, t.err, err)
continue
}
@@ -161,6 +197,10 @@ func main() {
for _, t := range floatTests {
x := t.f/t.g
if !alike(x, t.out) {
+ if !bad {
+ bad = true
+ fmt.Printf("BUG\n")
+ }
fmt.Printf("%v/%v: expected %g error; got %g\n", t.f, t.g, t.out, x)
}
}