Commit 4f61fc96 authored by Rob Pike's avatar Rob Pike

test: remove semiocolons.

The ken directory is untouched so we have some examples with explicit semis.

R=gri
CC=golang-dev
https://golang.org/cl/2157041
parent cd8f4cd2
This diff is collapsed.
...@@ -9,45 +9,45 @@ package main ...@@ -9,45 +9,45 @@ package main
import "sync" import "sync"
type T struct { type T struct {
int; int
sync.Mutex; sync.Mutex
} }
func main() { func main() {
{ {
var x, y sync.Mutex; var x, y sync.Mutex
x = y; // ERROR "assignment.*Mutex" x = y // ERROR "assignment.*Mutex"
_ = x; _ = x
} }
{ {
var x, y T; var x, y T
x = y; // ERROR "assignment.*Mutex" x = y // ERROR "assignment.*Mutex"
_ = x; _ = x
} }
{ {
var x, y [2]sync.Mutex; var x, y [2]sync.Mutex
x = y; // ERROR "assignment.*Mutex" x = y // ERROR "assignment.*Mutex"
_ = x; _ = x
} }
{ {
var x, y [2]T; var x, y [2]T
x = y; // ERROR "assignment.*Mutex" x = y // ERROR "assignment.*Mutex"
_ = x; _ = x
} }
{ {
x := sync.Mutex{0, 0}; // ERROR "assignment.*Mutex" x := sync.Mutex{0, 0} // ERROR "assignment.*Mutex"
_ = x; _ = x
} }
{ {
x := sync.Mutex{key: 0}; // ERROR "(unknown|assignment).*Mutex" x := sync.Mutex{key: 0} // ERROR "(unknown|assignment).*Mutex"
_ = x; _ = x
} }
{ {
x := &sync.Mutex{}; // ok x := &sync.Mutex{} // ok
var y sync.Mutex; // ok var y sync.Mutex // ok
y = *x; // ERROR "assignment.*Mutex" y = *x // ERROR "assignment.*Mutex"
*x = y; // ERROR "assignment.*Mutex" *x = y // ERROR "assignment.*Mutex"
_ = x; _ = x
_ = y; _ = y
} }
} }
...@@ -7,35 +7,35 @@ ...@@ -7,35 +7,35 @@
package main package main
type T struct { type T struct {
a float64; a float64
b int64; b int64
c string; c string
d byte; d byte
} }
var a = []int{ 1, 2, 3 } var a = []int{ 1, 2, 3 }
var NIL []int; var NIL []int
func arraycmptest() { func arraycmptest() {
if NIL != nil { if NIL != nil {
println("fail1:", NIL, "!= nil"); println("fail1:", NIL, "!= nil")
} }
if nil != NIL { if nil != NIL {
println("fail2: nil !=", NIL); println("fail2: nil !=", NIL)
} }
if a == nil || nil == a { if a == nil || nil == a {
println("fail3:", a, "== nil"); println("fail3:", a, "== nil")
} }
} }
func SameArray(a, b []int) bool { func SameArray(a, b []int) bool {
if len(a) != len(b) || cap(a) != cap(b) { if len(a) != len(b) || cap(a) != cap(b) {
return false; return false
} }
if len(a) > 0 && &a[0] != &b[0] { if len(a) > 0 && &a[0] != &b[0] {
return false; return false
} }
return true; return true
} }
var t = T{1.5, 123, "hello", 255} var t = T{1.5, 123, "hello", 255}
...@@ -43,16 +43,16 @@ var mt = make(map[int]T) ...@@ -43,16 +43,16 @@ var mt = make(map[int]T)
var ma = make(map[int][]int) var ma = make(map[int][]int)
func maptest() { func maptest() {
mt[0] = t; mt[0] = t
t1 := mt[0]; t1 := mt[0]
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { 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; ma[1] = a
a1 := ma[1]; a1 := ma[1]
if !SameArray(a, a1) { 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) ...@@ -60,21 +60,21 @@ var ct = make(chan T)
var ca = make(chan []int) var ca = make(chan []int)
func send() { func send() {
ct <- t; ct <- t
ca <- a; ca <- a
} }
func chantest() { 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 { 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) { 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 { } ...@@ -82,36 +82,36 @@ type E struct { }
var e E var e E
func interfacetest() { func interfacetest() {
var i interface{}; var i interface{}
i = a; i = a
a1 := i.([]int); a1 := i.([]int)
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("interface <-> []int", a, a1); println("interface <-> []int", a, a1)
} }
pa := new([]int); pa := new([]int)
*pa = a; *pa = a
i = pa; i = pa
a1 = *i.(*[]int); a1 = *i.(*[]int)
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("interface <-> *[]int", a, a1); println("interface <-> *[]int", a, a1)
} }
i = t; i = t
t1 := i.(T); t1 := i.(T)
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { 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; i = e
e1 := i.(E); e1 := i.(E)
// nothing to check; just verify it doesn't crash // nothing to check; just verify it doesn't crash
_ = e1; _ = e1
} }
func main() { func main() {
arraycmptest(); arraycmptest()
maptest(); maptest()
chantest(); chantest()
interfacetest(); interfacetest()
} }
...@@ -11,7 +11,7 @@ import _ "fmt" ...@@ -11,7 +11,7 @@ import _ "fmt"
var call string var call string
type T struct { type T struct {
_, _, _ int; _, _, _ int
} }
func (T) _() { func (T) _() {
...@@ -21,11 +21,11 @@ func (T) _() { ...@@ -21,11 +21,11 @@ func (T) _() {
} }
const ( const (
c0 = iota; c0 = iota
_; _
_; _
_; _
c4; c4
) )
var ints = []string { var ints = []string {
...@@ -35,12 +35,12 @@ var ints = []string { ...@@ -35,12 +35,12 @@ var ints = []string {
} }
func f() (int, int) { func f() (int, int) {
call += "f"; call += "f"
return 1,2 return 1,2
} }
func g() (float, float) { func g() (float, float) {
call += "g"; call += "g"
return 3,4 return 3,4
} }
...@@ -48,54 +48,54 @@ func h(_ int, _ float) { ...@@ -48,54 +48,54 @@ func h(_ int, _ float) {
} }
func i() int { func i() int {
call += "i"; call += "i"
return 23; return 23
} }
var _ = i(); var _ = i()
func main() { func main() {
if call != "i" {panic("init did not run")} if call != "i" {panic("init did not run")}
call = ""; call = ""
_, _ = f(); _, _ = f()
a, _ := f(); a, _ := f()
if a != 1 {panic(a)} if a != 1 {panic(a)}
b, _ := g(); b, _ := g()
if b != 3 {panic(b)} if b != 3 {panic(b)}
_, a = f(); _, a = f()
if a != 2 {panic(a)} if a != 2 {panic(a)}
_, b = g(); _, b = g()
if b != 4 {panic(b)} if b != 4 {panic(b)}
_ = i(); _ = i()
if call != "ffgfgi" {panic(call)} if call != "ffgfgi" {panic(call)}
if c4 != 4 {panic(c4)} if c4 != 4 {panic(c4)}
out := ""; out := ""
for _, s := range ints { for _, s := range ints {
out += s; out += s
} }
if out != "123" {panic(out)} if out != "123" {panic(out)}
sum := 0; sum := 0
for s, _ := range ints { for s, _ := range ints {
sum += s; sum += s
} }
if sum != 3 {panic(sum)} if sum != 3 {panic(sum)}
h(a,b); h(a,b)
} }
// useless but legal // useless but legal
var _ int = 1; var _ int = 1
var _ = 2; var _ = 2
var _, _ = 3, 4; var _, _ = 3, 4
const _ = 3; const _ = 3
const _, _ = 4, 5; const _, _ = 4, 5
type _ int; type _ int
func _() { func _() {
panic("oops") panic("oops")
} }
func ff() { func ff() {
var _ int = 1; var _ int = 1
} }
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
package _ // ERROR "invalid package name _" package _ // ERROR "invalid package name _"
func main() { func main() {
_(); // ERROR "cannot use _ as value" _() // ERROR "cannot use _ as value"
x := _+1; // ERROR "cannot use _ as value" x := _+1 // ERROR "cannot use _ as value"
} }
...@@ -13,20 +13,20 @@ import "os" ...@@ -13,20 +13,20 @@ import "os"
const N = 10 const N = 10
func AsynchFifo() { func AsynchFifo() {
ch := make(chan int, N); ch := make(chan int, N)
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
ch <- i ch <- i
} }
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
if <-ch != i { if <-ch != i {
print("bad receive\n"); print("bad receive\n")
os.Exit(1); os.Exit(1)
} }
} }
} }
func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) { func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) {
<-in; <-in
if <-ch != val { if <-ch != val {
panic(val) panic(val)
} }
...@@ -35,15 +35,15 @@ func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) { ...@@ -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 // thread together a daisy chain to read the elements in sequence
func SynchFifo() { func SynchFifo() {
ch := make(chan int); ch := make(chan int)
in := make(chan int); in := make(chan int)
start := in; start := in
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
out := make(chan int); out := make(chan int)
go Chain(ch, i, in, out); go Chain(ch, i, in, out)
in = out; in = out
} }
start <- 0; start <- 0
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
ch <- i ch <- i
} }
...@@ -51,7 +51,7 @@ func SynchFifo() { ...@@ -51,7 +51,7 @@ func SynchFifo() {
} }
func main() { func main() {
AsynchFifo(); AsynchFifo()
SynchFifo(); SynchFifo()
} }
...@@ -10,32 +10,32 @@ ...@@ -10,32 +10,32 @@
package main package main
import ( import (
"os"; "os"
"strconv"; "strconv"
) )
func f(left, right chan int) { func f(left, right chan int) {
left <- <-right; left <- <-right
} }
func main() { func main() {
var n = 10000; var n = 10000
if len(os.Args) > 1 { if len(os.Args) > 1 {
var err os.Error; var err os.Error
n, err = strconv.Atoi(os.Args[1]); n, err = strconv.Atoi(os.Args[1])
if err != nil { if err != nil {
print("bad arg\n"); print("bad arg\n")
os.Exit(1); os.Exit(1)
} }
} }
leftmost := make(chan int); leftmost := make(chan int)
right := leftmost; right := leftmost
left := leftmost; left := leftmost
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
right = make(chan int); right = make(chan int)
go f(left, right); go f(left, right)
left = right; left = right
} }
go func(c chan int) { c <- 1 }(right); go func(c chan int) { c <- 1 }(right)
<-leftmost; <-leftmost
} }
...@@ -7,51 +7,51 @@ ...@@ -7,51 +7,51 @@
package main package main
var ( var (
cr <-chan int; cr <-chan int
cs chan<- int; cs chan<- int
c chan int; c chan int
) )
func main() { func main() {
cr = c; // ok cr = c // ok
cs = c; // ok cs = c // ok
c = cr; // ERROR "illegal types|incompatible|cannot" c = cr // ERROR "illegal types|incompatible|cannot"
c = cs; // ERROR "illegal types|incompatible|cannot" c = cs // ERROR "illegal types|incompatible|cannot"
cr = cs; // ERROR "illegal types|incompatible|cannot" cr = cs // ERROR "illegal types|incompatible|cannot"
cs = cr; // ERROR "illegal types|incompatible|cannot" cs = cr // ERROR "illegal types|incompatible|cannot"
c <- 0; // ok c <- 0 // ok
ok := c <- 0; // ok ok := c <- 0 // ok
_ = ok; _ = ok
<-c; // ok <-c // ok
x, ok := <-c; // ok x, ok := <-c // ok
_, _ = x, ok; _, _ = x, ok
cr <- 0; // ERROR "send" cr <- 0 // ERROR "send"
ok = cr <- 0; // ERROR "send" ok = cr <- 0 // ERROR "send"
_ = ok; _ = ok
<-cr; // ok <-cr // ok
x, ok = <-cr; // ok x, ok = <-cr // ok
_, _ = x, ok; _, _ = x, ok
cs <- 0; // ok cs <- 0 // ok
ok = cs <- 0; // ok ok = cs <- 0 // ok
_ = ok; _ = ok
<-cs; // ERROR "receive" <-cs // ERROR "receive"
x, ok = <-cs; // ERROR "receive" x, ok = <-cs // ERROR "receive"
_, _ = x, ok; _, _ = x, ok
select { select {
case c <- 0: // ok case c <- 0: // ok
case x := <-c: // ok case x := <-c: // ok
_ = x; _ = x
case cr <- 0: // ERROR "send" case cr <- 0: // ERROR "send"
case x := <-cr: // ok case x := <-cr: // ok
_ = x; _ = x
case cs <- 0: // ok; case cs <- 0: // ok
case x := <-cs: // ERROR "receive" case x := <-cs: // ERROR "receive"
_ = x; _ = x
} }
} }
This diff is collapsed.
This diff is collapsed.
...@@ -32,13 +32,12 @@ func main() { ...@@ -32,13 +32,12 @@ func main() {
'\ubabe' + '\ubabe' +
'\U0010FFFF' + '\U0010FFFF' +
'\U000ebabe' '\U000ebabe'
;
if '\U000ebabe' != 0x000ebabe { if '\U000ebabe' != 0x000ebabe {
print("ebabe wrong\n"); print("ebabe wrong\n")
os.Exit(1) os.Exit(1)
} }
if i != 0x20e213 { if i != 0x20e213 {
print("number is ", i, " should be ", 0x20e213, "\n"); print("number is ", i, " should be ", 0x20e213, "\n")
os.Exit(1) os.Exit(1)
} }
} }
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
package main package main
type Chan interface { type Chan interface {
Send(int); Send(int)
Nbsend(int) bool; Nbsend(int) bool
Recv() int; Recv() int
Nbrecv() (int, bool); Nbrecv() (int, bool)
Close(); Close()
Closed() bool; Closed() bool
Impl() string; Impl() string
} }
// direct channel operations // direct channel operations
...@@ -28,7 +28,7 @@ func (c XChan) Send(x int) { ...@@ -28,7 +28,7 @@ func (c XChan) Send(x int) {
} }
func (c XChan) Nbsend(x int) bool { func (c XChan) Nbsend(x int) bool {
return c <- x; return c <- x
} }
func (c XChan) Recv() int { func (c XChan) Recv() int {
...@@ -36,8 +36,8 @@ func (c XChan) Recv() int { ...@@ -36,8 +36,8 @@ func (c XChan) Recv() int {
} }
func (c XChan) Nbrecv() (int, bool) { func (c XChan) Nbrecv() (int, bool) {
x, ok := <-c; x, ok := <-c
return x, ok; return x, ok
} }
func (c XChan) Close() { func (c XChan) Close() {
...@@ -63,29 +63,29 @@ func (c SChan) Send(x int) { ...@@ -63,29 +63,29 @@ func (c SChan) Send(x int) {
func (c SChan) Nbsend(x int) bool { func (c SChan) Nbsend(x int) bool {
select { select {
case c <- x: case c <- x:
return true; return true
default: default:
return false; return false
} }
panic("nbsend"); panic("nbsend")
} }
func (c SChan) Recv() int { func (c SChan) Recv() int {
select { select {
case x := <-c: case x := <-c:
return x; return x
} }
panic("recv"); panic("recv")
} }
func (c SChan) Nbrecv() (int, bool) { func (c SChan) Nbrecv() (int, bool) {
select { select {
case x := <-c: case x := <-c:
return x, true; return x, true
default: default:
return 0, false; return 0, false
} }
panic("nbrecv"); panic("nbrecv")
} }
func (c SChan) Close() { func (c SChan) Close() {
...@@ -97,101 +97,101 @@ func (c SChan) Closed() bool { ...@@ -97,101 +97,101 @@ func (c SChan) Closed() bool {
} }
func (c SChan) Impl() string { func (c SChan) Impl() string {
return "(select)"; return "(select)"
} }
func test1(c Chan) { func test1(c Chan) {
// not closed until the close signal (a zero value) has been received. // not closed until the close signal (a zero value) has been received.
if c.Closed() { 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++ { for i := 0; i < 3; i++ {
// recv a close signal (a zero value) // recv a close signal (a zero value)
if x := c.Recv(); x != 0 { 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. // should now be closed.
if !c.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. // should work with ,ok: received a value without blocking, so ok == true.
x, ok := c.Nbrecv(); x, ok := c.Nbrecv()
if !ok { 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 { 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. // send should work with ,ok too: sent a value without blocking, so ok == true.
ok := c.Nbsend(1); ok := c.Nbsend(1)
if !ok { 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. // but the value should have been discarded.
if x := c.Recv(); x != 0 { 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. // similarly Send.
c.Send(2); c.Send(2)
if x := c.Recv(); x != 0 { 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) { func testasync1(c Chan) {
// not closed until the close signal (a zero value) has been received. // not closed until the close signal (a zero value) has been received.
if c.Closed() { 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 // should be able to get the last value via Recv
if x := c.Recv(); x != 1 { 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) { func testasync2(c Chan) {
// not closed until the close signal (a zero value) has been received. // not closed until the close signal (a zero value) has been received.
if c.Closed() { 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 // should be able to get the last value via Nbrecv
if x, ok := c.Nbrecv(); !ok || x != 1 { 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 { func closedsync() chan int {
c := make(chan int); c := make(chan int)
close(c); close(c)
return c; return c
} }
func closedasync() chan int { func closedasync() chan int {
c := make(chan int, 2); c := make(chan int, 2)
c <- 1; c <- 1
close(c); close(c)
return c; return c
} }
func main() { func main() {
test1(XChan(closedsync())); test1(XChan(closedsync()))
test1(SChan(closedsync())); test1(SChan(closedsync()))
testasync1(XChan(closedasync())); testasync1(XChan(closedasync()))
testasync1(SChan(closedasync())); testasync1(SChan(closedasync()))
testasync2(XChan(closedasync())); testasync2(XChan(closedasync()))
testasync2(SChan(closedasync())); testasync2(SChan(closedasync()))
} }
...@@ -9,7 +9,7 @@ package main ...@@ -9,7 +9,7 @@ package main
func use(bool) { } func use(bool) { }
func main() { func main() {
var a []int; var a []int
var ia interface{} = a; var ia interface{} = a
use(ia == ia); use(ia == ia)
} }
...@@ -9,7 +9,7 @@ package main ...@@ -9,7 +9,7 @@ package main
func use(bool) { } func use(bool) { }
func main() { func main() {
var b []int; var b []int
var ib interface{} = b; var ib interface{} = b
use(ib == ib); use(ib == ib)
} }
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
package main package main
func main() { func main() {
var a []int; var a []int
var ia interface{} = a; var ia interface{} = a
var m = make(map[interface{}] int); var m = make(map[interface{}] int)
m[ia] = 1; m[ia] = 1
} }
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
package main package main
func main() { func main() {
var b []int; var b []int
var ib interface{} = b; var ib interface{} = b
var m = make(map[interface{}] int); var m = make(map[interface{}] int)
m[ib] = 1; m[ib] = 1
} }
...@@ -11,9 +11,9 @@ type T struct { i int; f float; s string; next *T } ...@@ -11,9 +11,9 @@ type T struct { i int; f float; s string; next *T }
type R struct { num int } type R struct { num int }
func itor(a int) *R { func itor(a int) *R {
r := new(R); r := new(R)
r.num = a; r.num = a
return r; return r
} }
func eq(a []*R) { func eq(a []*R) {
...@@ -22,49 +22,49 @@ 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 { func NewP(a, b int) *P {
return &P{a, b} return &P{a, b}
} }
func main() { func main() {
var t T; var t T
t = T{0, 7.2, "hi", &t}; t = T{0, 7.2, "hi", &t}
var tp *T; var tp *T
tp = &T{0, 7.2, "hi", &t}; tp = &T{0, 7.2, "hi", &t}
a1 := []int{1,2,3}; a1 := []int{1,2,3}
if len(a1) != 3 { panic("a1") } 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") } 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") } if len(a3) != 10 || a2[3] != 0 { panic("a3") }
var oai []int; var oai []int
oai = []int{1,2,3}; oai = []int{1,2,3}
if len(oai) != 3 { panic("oai") } if len(oai) != 3 { panic("oai") }
at := [...]*T{&t, tp, &t}; at := [...]*T{&t, tp, &t}
if len(at) != 3 { panic("at") } if len(at) != 3 { panic("at") }
c := make(chan int); c := make(chan int)
ac := []chan int{c, c, c}; ac := []chan int{c, c, c}
if len(ac) != 3 { panic("ac") } 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") } 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") } 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") } 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); p1 := NewP(1, 2)
p2 := NewP(1, 2); p2 := NewP(1, 2)
if p1 == p2 { panic("NewP") } if p1 == p2 { panic("NewP") }
} }
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
package main package main
type T struct { type T struct {
int; int
} }
func f() *T { func f() *T {
...@@ -15,9 +15,9 @@ func f() *T { ...@@ -15,9 +15,9 @@ func f() *T {
} }
func main() { func main() {
x := f(); x := f()
y := f(); y := f()
if x == y { if x == y {
panic("not allocating & composite literals"); panic("not allocating & composite literals")
} }
} }
...@@ -7,26 +7,26 @@ ...@@ -7,26 +7,26 @@
package main package main
const ( const (
c0 = 0; c0 = 0
cm1 = -1; cm1 = -1
chuge = 1 << 100; chuge = 1 << 100
chuge_1 = chuge - 1; chuge_1 = chuge - 1
c1 = chuge >> 100; c1 = chuge >> 100
c3div2 = 3/2; c3div2 = 3/2
c1e3 = 1e3; c1e3 = 1e3
ctrue = true; ctrue = true
cfalse = !ctrue; cfalse = !ctrue
) )
const ( const (
f0 = 0.0; f0 = 0.0
fm1 = -1.; fm1 = -1.
fhuge float64 = 1 << 100; fhuge float64 = 1 << 100
fhuge_1 float64 = chuge - 1; fhuge_1 float64 = chuge - 1
f1 float64 = chuge >> 100; f1 float64 = chuge >> 100
f3div2 = 3./2.; f3div2 = 3./2.
f1e3 float64 = 1e3; f1e3 float64 = 1e3
) )
func assert(t bool, s string) { func assert(t bool, s string) {
...@@ -36,85 +36,85 @@ func assert(t bool, s string) { ...@@ -36,85 +36,85 @@ func assert(t bool, s string) {
} }
func ints() { func ints() {
assert(c0 == 0, "c0"); assert(c0 == 0, "c0")
assert(c1 == 1, "c1"); assert(c1 == 1, "c1")
assert(chuge > chuge_1, "chuge"); assert(chuge > chuge_1, "chuge")
assert(chuge_1 + 1 == chuge, "chuge 1"); assert(chuge_1 + 1 == chuge, "chuge 1")
assert(chuge + cm1 +1 == chuge, "cm1"); assert(chuge + cm1 +1 == chuge, "cm1")
assert(c3div2 == 1, "3/2"); assert(c3div2 == 1, "3/2")
assert(c1e3 == 1000, "c1e3 int"); assert(c1e3 == 1000, "c1e3 int")
assert(c1e3 == 1e3, "c1e3 float"); assert(c1e3 == 1e3, "c1e3 float")
// verify that all (in range) are assignable as ints // verify that all (in range) are assignable as ints
var i int; var i int
i = c0; i = c0
assert(i == c0, "i == c0"); assert(i == c0, "i == c0")
i = cm1; i = cm1
assert(i == cm1, "i == cm1"); assert(i == cm1, "i == cm1")
i = c1; i = c1
assert(i == c1, "i == c1"); assert(i == c1, "i == c1")
i = c3div2; i = c3div2
assert(i == c3div2, "i == c3div2"); assert(i == c3div2, "i == c3div2")
i = c1e3; i = c1e3
assert(i == c1e3, "i == c1e3"); assert(i == c1e3, "i == c1e3")
// verify that all are assignable as floats // verify that all are assignable as floats
var f float64; var f float64
f = c0; f = c0
assert(f == c0, "f == c0"); assert(f == c0, "f == c0")
f = cm1; f = cm1
assert(f == cm1, "f == cm1"); assert(f == cm1, "f == cm1")
f = chuge; f = chuge
assert(f == chuge, "f == chuge"); assert(f == chuge, "f == chuge")
f = chuge_1; f = chuge_1
assert(f == chuge_1, "f == chuge_1"); assert(f == chuge_1, "f == chuge_1")
f = c1; f = c1
assert(f == c1, "f == c1"); assert(f == c1, "f == c1")
f = c3div2; f = c3div2
assert(f == c3div2, "f == c3div2"); assert(f == c3div2, "f == c3div2")
f = c1e3; f = c1e3
assert(f == c1e3, "f == c1e3"); assert(f == c1e3, "f == c1e3")
} }
func floats() { func floats() {
assert(f0 == c0, "f0"); assert(f0 == c0, "f0")
assert(f1 == c1, "f1"); assert(f1 == c1, "f1")
assert(fhuge == fhuge_1, "fhuge"); // float64 can't distinguish fhuge, fhuge_1. assert(fhuge == fhuge_1, "fhuge") // float64 can't distinguish fhuge, fhuge_1.
assert(fhuge_1 + 1 == fhuge, "fhuge 1"); assert(fhuge_1 + 1 == fhuge, "fhuge 1")
assert(fhuge + fm1 +1 == fhuge, "fm1"); assert(fhuge + fm1 +1 == fhuge, "fm1")
assert(f3div2 == 1.5, "3./2."); assert(f3div2 == 1.5, "3./2.")
assert(f1e3 == 1000, "f1e3 int"); assert(f1e3 == 1000, "f1e3 int")
assert(f1e3 == 1.e3, "f1e3 float"); assert(f1e3 == 1.e3, "f1e3 float")
// verify that all (in range) are assignable as ints // verify that all (in range) are assignable as ints
var i int; var i int
i = f0; i = f0
assert(i == f0, "i == f0"); assert(i == f0, "i == f0")
i = fm1; i = fm1
assert(i == fm1, "i == fm1"); assert(i == fm1, "i == fm1")
// verify that all are assignable as floats // verify that all are assignable as floats
var f float64; var f float64
f = f0; f = f0
assert(f == f0, "f == f0"); assert(f == f0, "f == f0")
f = fm1; f = fm1
assert(f == fm1, "f == fm1"); assert(f == fm1, "f == fm1")
f = fhuge; f = fhuge
assert(f == fhuge, "f == fhuge"); assert(f == fhuge, "f == fhuge")
f = fhuge_1; f = fhuge_1
assert(f == fhuge_1, "f == fhuge_1"); assert(f == fhuge_1, "f == fhuge_1")
f = f1; f = f1
assert(f == f1, "f == f1"); assert(f == f1, "f == f1")
f = f3div2; f = f3div2
assert(f == f3div2, "f == f3div2"); assert(f == f3div2, "f == f3div2")
f = f1e3; f = f1e3
assert(f == f1e3, "f == f1e3"); assert(f == f1e3, "f == f1e3")
} }
func main() { func main() {
ints(); ints()
floats(); floats()
assert(ctrue == true, "ctrue == true"); assert(ctrue == true, "ctrue == true")
assert(cfalse == false, "cfalse == false"); assert(cfalse == false, "cfalse == false")
} }
...@@ -9,71 +9,71 @@ package main ...@@ -9,71 +9,71 @@ package main
type I interface {} type I interface {}
const ( const (
// assume all types behave similarly to int8/uint8 // assume all types behave similarly to int8/uint8
Int8 int8 = 101; Int8 int8 = 101
Minus1 int8 = -1; Minus1 int8 = -1
Uint8 uint8 = 102; Uint8 uint8 = 102
Const = 103; Const = 103
Float32 float32 = 104.5; Float32 float32 = 104.5
Float float = 105.5; Float float = 105.5
ConstFloat = 106.5; ConstFloat = 106.5
Big float64 = 1e300; Big float64 = 1e300
String = "abc"; String = "abc"
Bool = true; Bool = true
) )
var ( var (
a1 = Int8 * 100; // ERROR "overflow" a1 = Int8 * 100 // ERROR "overflow"
a2 = Int8 * -1; // OK a2 = Int8 * -1 // OK
a3 = Int8 * 1000; // ERROR "overflow" a3 = Int8 * 1000 // ERROR "overflow"
a4 = Int8 * int8(1000); // ERROR "overflow" a4 = Int8 * int8(1000) // ERROR "overflow"
a5 = int8(Int8 * 1000); // ERROR "overflow" a5 = int8(Int8 * 1000) // ERROR "overflow"
a6 = int8(Int8 * int8(1000)); // ERROR "overflow" a6 = int8(Int8 * int8(1000)) // ERROR "overflow"
a7 = Int8 - 2*Int8 - 2*Int8; // ERROR "overflow" a7 = Int8 - 2*Int8 - 2*Int8 // ERROR "overflow"
a8 = Int8 * Const / 100; // ERROR "overflow" a8 = Int8 * Const / 100 // ERROR "overflow"
a9 = Int8 * (Const / 100); // OK a9 = Int8 * (Const / 100) // OK
b1 = Uint8 * Uint8; // ERROR "overflow" b1 = Uint8 * Uint8 // ERROR "overflow"
b2 = Uint8 * -1; // ERROR "overflow" b2 = Uint8 * -1 // ERROR "overflow"
b3 = Uint8 - Uint8; // OK b3 = Uint8 - Uint8 // OK
b4 = Uint8 - Uint8 - Uint8; // ERROR "overflow" b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
b5 = uint8(^0); // ERROR "overflow" b5 = uint8(^0) // ERROR "overflow"
b6 = ^uint8(0); // OK b6 = ^uint8(0) // OK
b7 = uint8(Minus1); // ERROR "overflow" b7 = uint8(Minus1) // ERROR "overflow"
b8 = uint8(int8(-1)); // ERROR "overflow" b8 = uint8(int8(-1)) // ERROR "overflow"
b8a = uint8(-1); // ERROR "overflow" b8a = uint8(-1) // ERROR "overflow"
b9 byte = (1<<10) >> 8; // OK b9 byte = (1<<10) >> 8 // OK
b10 byte = (1<<10); // ERROR "overflow" b10 byte = (1<<10) // ERROR "overflow"
b11 byte = (byte(1)<<10) >> 8; // ERROR "overflow" b11 byte = (byte(1)<<10) >> 8 // ERROR "overflow"
b12 byte = 1000; // ERROR "overflow" b12 byte = 1000 // ERROR "overflow"
b13 byte = byte(1000); // ERROR "overflow" b13 byte = byte(1000) // ERROR "overflow"
b14 byte = byte(100) * byte(100); // ERROR "overflow" b14 byte = byte(100) * byte(100) // ERROR "overflow"
b15 byte = byte(100) * 100; // ERROR "overflow" b15 byte = byte(100) * 100 // ERROR "overflow"
b16 byte = byte(0) * 1000; // ERROR "overflow" b16 byte = byte(0) * 1000 // ERROR "overflow"
b16a byte = 0 * 1000; // OK b16a byte = 0 * 1000 // OK
b17 byte = byte(0) * byte(1000); // ERROR "overflow" b17 byte = byte(0) * byte(1000) // ERROR "overflow"
b18 byte = Uint8/0; // ERROR "division by zero" b18 byte = Uint8/0 // ERROR "division by zero"
c1 float64 = Big; c1 float64 = Big
c2 float64 = Big*Big; // ERROR "overflow" c2 float64 = Big*Big // ERROR "overflow"
c3 float64 = float64(Big)*Big; // ERROR "overflow" c3 float64 = float64(Big)*Big // ERROR "overflow"
c4 = Big*Big; // ERROR "overflow" c4 = Big*Big // ERROR "overflow"
c5 = Big/0; // ERROR "division by zero" c5 = Big/0 // ERROR "division by zero"
) )
func f(int); func f(int)
func main() { func main() {
f(Int8); // ERROR "convert|wrong type|cannot" f(Int8) // ERROR "convert|wrong type|cannot"
f(Minus1); // ERROR "convert|wrong type|cannot" f(Minus1) // ERROR "convert|wrong type|cannot"
f(Uint8); // ERROR "convert|wrong type|cannot" f(Uint8) // ERROR "convert|wrong type|cannot"
f(Const); // OK f(Const) // OK
f(Float32); // ERROR "convert|wrong type|cannot" f(Float32) // ERROR "convert|wrong type|cannot"
f(Float); // ERROR "convert|wrong type|cannot" f(Float) // ERROR "convert|wrong type|cannot"
f(ConstFloat); // ERROR "truncate" f(ConstFloat) // ERROR "truncate"
f(ConstFloat - 0.5); // OK f(ConstFloat - 0.5) // OK
f(Big); // ERROR "convert|wrong type|cannot" f(Big) // ERROR "convert|wrong type|cannot"
f(String); // ERROR "convert|wrong type|cannot|incompatible" f(String) // ERROR "convert|wrong type|cannot|incompatible"
f(Bool); // ERROR "convert|wrong type|cannot|incompatible" f(Bool) // ERROR "convert|wrong type|cannot|incompatible"
} }
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
package main package main
const ( const (
A int = 1; A int = 1
B byte; // ERROR "type without expr|expected .=." B byte; // ERROR "type without expr|expected .=."
) )
...@@ -9,31 +9,31 @@ package main ...@@ -9,31 +9,31 @@ package main
// explicit conversion of constants is work in progress. // explicit conversion of constants is work in progress.
// the ERRORs in this block are debatable, but they're what // the ERRORs in this block are debatable, but they're what
// the language spec says for now. // the language spec says for now.
var x1 = string(1); var x1 = string(1)
var x2 string = string(1); var x2 string = string(1)
var x3 = int(1.5); // ERROR "convert|truncate" var x3 = int(1.5) // ERROR "convert|truncate"
var x4 int = int(1.5); // ERROR "convert|truncate" var x4 int = int(1.5) // ERROR "convert|truncate"
var x5 = "a" + string(1); var x5 = "a" + string(1)
var x6 = int(1e100); // ERROR "overflow" var x6 = int(1e100) // ERROR "overflow"
var x7 = float(1e1000); // ERROR "overflow" var x7 = float(1e1000) // ERROR "overflow"
// implicit conversions merit scrutiny // implicit conversions merit scrutiny
var s string; var s string
var bad1 string = 1; // ERROR "conver|incompatible|invalid|cannot" var bad1 string = 1 // ERROR "conver|incompatible|invalid|cannot"
var bad2 = s + 1; // ERROR "conver|incompatible|invalid" var bad2 = s + 1 // ERROR "conver|incompatible|invalid"
var bad3 = s + 'a'; // ERROR "conver|incompatible|invalid" var bad3 = s + 'a' // ERROR "conver|incompatible|invalid"
var bad4 = "a" + 1; // ERROR "literals|incompatible|convert|invalid" var bad4 = "a" + 1 // ERROR "literals|incompatible|convert|invalid"
var bad5 = "a" + 'a'; // ERROR "literals|incompatible|convert|invalid" var bad5 = "a" + 'a' // ERROR "literals|incompatible|convert|invalid"
var bad6 int = 1.5; // ERROR "convert|truncate" var bad6 int = 1.5 // ERROR "convert|truncate"
var bad7 int = 1e100; // ERROR "overflow" var bad7 int = 1e100 // ERROR "overflow"
var bad8 float32 = 1e200; // ERROR "overflow" var bad8 float32 = 1e200 // ERROR "overflow"
// but these implicit conversions are okay // but these implicit conversions are okay
var good1 string = "a"; var good1 string = "a"
var good2 int = 1.0; var good2 int = 1.0
var good3 int = 1e9; var good3 int = 1e9
var good4 float = 1e20; var good4 float = 1e20
// explicit conversion of string is okay // explicit conversion of string is okay
var _ = []int("abc") var _ = []int("abc")
......
...@@ -13,28 +13,28 @@ func f2() (float, int) { return 1, 2 } ...@@ -13,28 +13,28 @@ func f2() (float, int) { return 1, 2 }
func f3() (float, int, string) { return 1, 2, "3" } func f3() (float, int, string) { return 1, 2, "3" }
func x() (s string) { func x() (s string) {
a, b, s := f3(); a, b, s := f3()
_, _ = a, b; _, _ = a, b
return // tests that result var is in scope for redeclaration return // tests that result var is in scope for redeclaration
} }
func main() { func main() {
i, f, s := f3(); i, f, s := f3()
j, f := f2(); // redeclare f j, f := f2() // redeclare f
k := f1(); k := f1()
m, g, s := f3(); m, g, s := f3()
m, h, s := f3(); m, h, s := f3()
{ {
// new block should be ok. // new block should be ok.
i, f, s := f3(); i, f, s := f3()
j, f := f2(); // redeclare f j, f := f2() // redeclare f
k := f1(); k := f1()
m, g, s := f3(); m, g, s := f3()
m, h, s := f3(); m, h, s := f3()
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h; _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
} }
if x() != "3" { 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
} }
...@@ -15,44 +15,44 @@ func f3() (float, int, string) { return 1, 2, "3" } ...@@ -15,44 +15,44 @@ func f3() (float, int, string) { return 1, 2, "3" }
func main() { func main() {
{ {
// simple redeclaration // simple redeclaration
i := f1(); i := f1()
i := f1(); // ERROR "redeclared|no new" i := f1() // ERROR "redeclared|no new"
_ = i; _ = i
} }
{ {
// change of type for f // change of type for f
i, f, s := f3(); i, f, s := f3()
f, g, t := f3(); // ERROR "redeclared|cannot assign|incompatible" f, g, t := f3() // ERROR "redeclared|cannot assign|incompatible"
_, _, _, _, _ = i, f, s, g, t; _, _, _, _, _ = i, f, s, g, t
} }
{ {
// change of type for i // change of type for i
i, f, s := f3(); i, f, s := f3()
j, i, t := f3(); // ERROR "redeclared|cannot assign|incompatible" j, i, t := f3() // ERROR "redeclared|cannot assign|incompatible"
_, _, _, _, _ = i, f, s, j, t; _, _, _, _, _ = i, f, s, j, t
} }
{ {
// no new variables // no new variables
i, f, s := f3(); i, f, s := f3()
i, f := f2(); // ERROR "redeclared|no new" i, f := f2() // ERROR "redeclared|no new"
_, _, _ = i, f, s; _, _, _ = i, f, s
} }
{ {
// single redeclaration // single redeclaration
i, f, s := f3(); i, f, s := f3()
i := f1(); // ERROR "redeclared|no new|incompatible" i := f1() // ERROR "redeclared|no new|incompatible"
_, _, _ = i, f, s; _, _, _ = i, f, s
} }
// double redeclaration // double redeclaration
{ {
i, f, s := f3(); i, f, s := f3()
i, f := f2(); // ERROR "redeclared|no new" i, f := f2() // ERROR "redeclared|no new"
_, _, _ = i, f, s; _, _, _ = i, f, s
} }
{ {
// triple redeclaration // triple redeclaration
i, f, s := f3(); i, f, s := f3()
i, f, s := f3(); // ERROR "redeclared|no new" i, f, s := f3() // ERROR "redeclared|no new"
_, _, _ = i, f, s; _, _, _ = i, f, s
} }
} }
...@@ -10,18 +10,18 @@ package main ...@@ -10,18 +10,18 @@ package main
import os "os" import os "os"
func main() { func main() {
ga, e0 := os.Getenverror("GOARCH"); ga, e0 := os.Getenverror("GOARCH")
if e0 != nil { if e0 != nil {
print("$GOARCH: ", e0.String(), "\n"); print("$GOARCH: ", e0.String(), "\n")
os.Exit(1); os.Exit(1)
} }
if ga != "amd64" && ga != "386" && ga != "arm" { if ga != "amd64" && ga != "386" && ga != "arm" {
print("$GOARCH=", ga, "\n"); print("$GOARCH=", ga, "\n")
os.Exit(1); os.Exit(1)
} }
xxx, e1 := os.Getenverror("DOES_NOT_EXIST"); xxx, e1 := os.Getenverror("DOES_NOT_EXIST")
if e1 != os.ENOENV { if e1 != os.ENOENV {
print("$DOES_NOT_EXIST=", xxx, "; err = ", e1.String(), "\n"); print("$DOES_NOT_EXIST=", xxx, "; err = ", e1.String(), "\n")
os.Exit(1); os.Exit(1)
} }
} }
...@@ -14,142 +14,142 @@ package main ...@@ -14,142 +14,142 @@ package main
var bad = false var bad = false
var allptr = make([]*int, 0, 100); var allptr = make([]*int, 0, 100)
func noalias(p, q *int, s string) { func noalias(p, q *int, s string) {
n := len(allptr); n := len(allptr)
*p = -(n+1); *p = -(n+1)
*q = -(n+2); *q = -(n+2)
allptr = allptr[0:n+2]; allptr = allptr[0:n+2]
allptr[n] = p; allptr[n] = p
allptr[n+1] = q; allptr[n+1] = q
n += 2; n += 2
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
if allptr[i] != nil && *allptr[i] != -(i+1) { if allptr[i] != nil && *allptr[i] != -(i+1) {
println("aliased pointers", -(i+1), *allptr[i], "after", s); println("aliased pointers", -(i+1), *allptr[i], "after", s)
allptr[i] = nil; allptr[i] = nil
bad = true; bad = true
} }
} }
} }
func val(p, q *int, v int, s string) { func val(p, q *int, v int, s string) {
if *p != v { if *p != v {
println("wrong value want", v, "got", *p, "after", s); println("wrong value want", v, "got", *p, "after", s)
bad = true; bad = true
} }
if *q != v+1 { if *q != v+1 {
println("wrong value want", v+1, "got", *q, "after", s); println("wrong value want", v+1, "got", *q, "after", s)
bad = true; bad = true
} }
} }
func chk(p, q *int, v int, s string) { func chk(p, q *int, v int, s string) {
val(p, q, v, s); val(p, q, v, s)
noalias(p, q, s); noalias(p, q, s)
} }
func chkalias(p, q *int, v int, s string) { func chkalias(p, q *int, v int, s string) {
if p != q { 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 { 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 { func i_escapes(x int) *int {
var i int; var i int
i = x; i = x
return &i; return &i
} }
func j_escapes(x int) *int { func j_escapes(x int) *int {
var j int = x; var j int = x
j = x; j = x
return &j; return &j
} }
func k_escapes(x int) *int { func k_escapes(x int) *int {
k := x; k := x
return &k; return &k
} }
func in_escapes(x int) *int { func in_escapes(x int) *int {
return &x; return &x
} }
func send(c chan int, x int) { func send(c chan int, x int) {
c <- x; c <- x
} }
func select_escapes(x int) *int { func select_escapes(x int) *int {
c := make(chan int); c := make(chan int)
go send(c, x); go send(c, x)
select { select {
case req := <-c: case req := <-c:
return &req; return &req
} }
return nil; return nil
} }
func select_escapes1(x int, y int) (*int, *int) { func select_escapes1(x int, y int) (*int, *int) {
c := make(chan int); c := make(chan int)
var a [2]int; var a [2]int
var p [2]*int; var p [2]*int
a[0] = x; a[0] = x
a[1] = y; a[1] = y
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
go send(c, a[i]); go send(c, a[i])
select { select {
case req := <-c: case req := <-c:
p[i] = &req; p[i] = &req
} }
} }
return p[0], p[1] return p[0], p[1]
} }
func range_escapes(x int) *int { func range_escapes(x int) *int {
var a [1]int; var a [1]int
a[0] = x; a[0] = x
for _, v := range a { for _, v := range a {
return &v; return &v
} }
return nil; return nil
} }
// *is* aliased // *is* aliased
func range_escapes2(x, y int) (*int, *int) { func range_escapes2(x, y int) (*int, *int) {
var a [2]int; var a [2]int
var p [2]*int; var p [2]*int
a[0] = x; a[0] = x
a[1] = y; a[1] = y
for k, v := range a { for k, v := range a {
p[k] = &v; p[k] = &v
} }
return p[0], p[1] return p[0], p[1]
} }
// *is* aliased // *is* aliased
func for_escapes2(x int, y int) (*int, *int) { func for_escapes2(x int, y int) (*int, *int) {
var p [2]*int; var p [2]*int
n := 0; n := 0
for i := x; n < 2; i = y { for i := x; n < 2; i = y {
p[n] = &i; p[n] = &i
n++; n++
} }
return p[0], p[1] return p[0], p[1]
} }
func out_escapes(i int) (x int, p *int) { func out_escapes(i int) (x int, p *int) {
x = i x = i
p = &x; // ERROR "address of out parameter" p = &x // ERROR "address of out parameter"
return; return
} }
func out_escapes_2(i int) (x int, p *int) { func out_escapes_2(i int) (x int, p *int) {
x = i x = i
return x, &x; // ERROR "address of out parameter" return x, &x // ERROR "address of out parameter"
} }
func defer1(i int) (x int) { func defer1(i int) (x int) {
...@@ -160,40 +160,40 @@ func defer1(i int) (x int) { ...@@ -160,40 +160,40 @@ func defer1(i int) (x int) {
} }
func main() { func main() {
p, q := i_escapes(1), i_escapes(2); p, q := i_escapes(1), i_escapes(2)
chk(p, q, 1, "i_escapes"); chk(p, q, 1, "i_escapes")
p, q = j_escapes(3), j_escapes(4); p, q = j_escapes(3), j_escapes(4)
chk(p, q, 3, "j_escapes"); chk(p, q, 3, "j_escapes")
p, q = k_escapes(5), k_escapes(6); p, q = k_escapes(5), k_escapes(6)
chk(p, q, 5, "k_escapes"); chk(p, q, 5, "k_escapes")
p, q = in_escapes(7), in_escapes(8); p, q = in_escapes(7), in_escapes(8)
chk(p, q, 7, "in_escapes"); chk(p, q, 7, "in_escapes")
p, q = select_escapes(9), select_escapes(10); p, q = select_escapes(9), select_escapes(10)
chk(p, q, 9, "select_escapes"); chk(p, q, 9, "select_escapes")
p, q = select_escapes1(11, 12); p, q = select_escapes1(11, 12)
chk(p, q, 11, "select_escapes1"); chk(p, q, 11, "select_escapes1")
p, q = range_escapes(13), range_escapes(14); p, q = range_escapes(13), range_escapes(14)
chk(p, q, 13, "range_escapes"); chk(p, q, 13, "range_escapes")
p, q = range_escapes2(101, 102); p, q = range_escapes2(101, 102)
chkalias(p, q, 101, "range_escapes2"); chkalias(p, q, 101, "range_escapes2")
p, q = for_escapes2(103, 104); p, q = for_escapes2(103, 104)
chkalias(p, q, 103, "for_escapes2"); chkalias(p, q, 103, "for_escapes2")
_, p = out_escapes(15) _, p = out_escapes(15)
_, q = out_escapes(16); _, q = out_escapes(16)
chk(p, q, 15, "out_escapes"); chk(p, q, 15, "out_escapes")
_, p = out_escapes_2(17) _, p = out_escapes_2(17)
_, q = out_escapes_2(18); _, q = out_escapes_2(18)
chk(p, q, 17, "out_escapes_2"); chk(p, q, 17, "out_escapes_2")
x := defer1(20) x := defer1(20)
if x != 20 { if x != 20 {
...@@ -202,6 +202,6 @@ func main() { ...@@ -202,6 +202,6 @@ func main() {
} }
if bad { if bad {
panic("BUG: no escape"); panic("BUG: no escape")
} }
} }
...@@ -24,34 +24,34 @@ func ...@@ -24,34 +24,34 @@ func
pow10(pow int) float64 { pow10(pow int) float64 {
if pow < 0 { return 1/pow10(-pow); } if pow < 0 { return 1/pow10(-pow); }
if pow > 0 { return pow10(pow-1)*10; } if pow > 0 { return pow10(pow-1)*10; }
return 1; return 1
} }
func func
close(da float64, ia, ib int64, pow int) bool { close(da float64, ia, ib int64, pow int) bool {
db := float64(ia) / float64(ib); db := float64(ia) / float64(ib)
db *= pow10(pow); db *= pow10(pow)
if da == 0 || db == 0 { if da == 0 || db == 0 {
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 { if de < 0 {
de = -de; de = -de
} }
if de < deLim { if de < deLim {
return true; return true
} }
if !bad { if !bad {
println("BUG") println("BUG")
bad = true bad = true
} }
return false; return false
} }
func func
......
...@@ -8,49 +8,49 @@ package main ...@@ -8,49 +8,49 @@ package main
func assertequal(is, shouldbe int, msg string) { func assertequal(is, shouldbe int, msg string) {
if is != shouldbe { if is != shouldbe {
print("assertion fail", msg, "\n"); print("assertion fail", msg, "\n")
panic(1); panic(1)
} }
} }
func main() { func main() {
var i, sum int; var i, sum int
i = 0; i = 0
for { for {
i = i + 1; i = i + 1
if i > 5 { if i > 5 {
break; break
} }
} }
assertequal(i, 6, "break"); assertequal(i, 6, "break")
sum = 0; sum = 0
for i := 0; i <= 10; i++ { 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; { for i := 0; i <= 10; {
sum = sum + i; sum = sum + i
i++; i++
} }
assertequal(sum, 55, "only two"); assertequal(sum, 55, "only two")
sum = 0; sum = 0
for sum < 100 { 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++ { for i := 0; i <= 10; i++ {
if i % 2 == 0 { 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")
} }
...@@ -9,8 +9,8 @@ package main ...@@ -9,8 +9,8 @@ package main
func assertequal(is, shouldbe int, msg string) { func assertequal(is, shouldbe int, msg string) {
if is != shouldbe { if is != shouldbe {
print("assertion fail", msg, "\n"); print("assertion fail", msg, "\n")
panic(1); panic(1)
} }
} }
...@@ -21,69 +21,69 @@ func f2(a int) { ...@@ -21,69 +21,69 @@ func f2(a int) {
} }
func f3(a, b int) int { func f3(a, b int) int {
return a+b; return a+b
} }
func f4(a, b int, c float) int { 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 { func f5(a int) int {
return 5; return 5
} }
func f6(a int) (r int) { func f6(a int) (r int) {
return 6; return 6
} }
func f7(a int) (x int, y float) { func f7(a int) (x int, y float) {
return 7, 7.0; return 7, 7.0
} }
func f8(a int) (x int, y float) { func f8(a int) (x int, y float) {
return 8, 8.0; return 8, 8.0
} }
type T struct { type T struct {
x, y int; x, y int
} }
func (t *T) m10(a int, b float) 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) { func f9(a int) (i int, f float) {
i = 9; i = 9
f = 9.0; f = 9.0
return; return
} }
func main() { func main() {
f1(); f1()
f2(1); f2(1)
r3 := f3(1, 2); r3 := f3(1, 2)
assertequal(r3, 3, "3"); assertequal(r3, 3, "3")
r4 := f4(0, 2, 3.0); r4 := f4(0, 2, 3.0)
assertequal(r4, 4, "4"); assertequal(r4, 4, "4")
r5 := f5(1); r5 := f5(1)
assertequal(r5, 5, "5"); assertequal(r5, 5, "5")
r6 := f6(1); r6 := f6(1)
assertequal(r6, 6, "6"); assertequal(r6, 6, "6")
r7, s7 := f7(1); r7, s7 := f7(1)
assertequal(r7, 7, "r7"); assertequal(r7, 7, "r7")
assertequal(int(s7), 7, "s7"); assertequal(int(s7), 7, "s7")
r8, s8 := f8(1); r8, s8 := f8(1)
assertequal(r8, 8, "r8"); assertequal(r8, 8, "r8")
assertequal(int(s8), 8, "s8"); assertequal(int(s8), 8, "s8")
r9, s9 := f9(1); r9, s9 := f9(1)
assertequal(r9, 9, "r9"); assertequal(r9, 9, "r9")
assertequal(int(s9), 9, "s9"); assertequal(int(s9), 9, "s9")
var t *T = new(T); var t *T = new(T)
t.x = 1; t.x = 1
t.y = 2; t.y = 2
r10 := t.m10(1, 3.0); r10 := t.m10(1, 3.0)
assertequal(r10, 10, "10"); assertequal(r10, 10, "10")
} }
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
package main package main
func f1(a int) (int, float) { // BUG (not caught by compiler): multiple return values must have names 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" func f2(a int) (a int, b float) { // ERROR "redeclared|definition"
return 8, 8.0; return 8, 8.0
} }
...@@ -5,20 +5,20 @@ ...@@ -5,20 +5,20 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package main
import os "os"; import os "os"
type t1 int; type t1 int
type t2 int; type t2 int
type t3 int; type t3 int
func f1(t1, t2, t3); func f1(t1, t2, t3)
func f2(t1, t2, t3 bool); func f2(t1, t2, t3 bool)
func f3(t1, t2, x t3); func f3(t1, t2, x t3)
func f4(t1, *t3); func f4(t1, *t3)
func (x *t1) f5(y []t2) (t1, *t3); func (x *t1) f5(y []t2) (t1, *t3)
func f6() (int, *string); func f6() (int, *string)
func f7(*t2, t3); func f7(*t2, t3)
func f8(os int) int; func f8(os int) int
func f9(os int) int { func f9(os int) int {
return os return os
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
package main package main
type t1 int; type t1 int
type t2 int; type t2 int
type t3 int; type t3 int
func f1(*t2, x t3); // ERROR "named" func f1(*t2, x t3) // ERROR "named"
func f2(t1, *t2, x t3); // ERROR "named" func f2(t1, *t2, x t3) // ERROR "named"
func f3() (x int, *string); // 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.
...@@ -9,6 +9,6 @@ package main ...@@ -9,6 +9,6 @@ package main
var notmain func() var notmain func()
func main() { func main() {
var x = &main; // ERROR "address of|invalid" var x = &main // ERROR "address of|invalid"
main = notmain; // ERROR "assign to|invalid" main = notmain // ERROR "assign to|invalid"
} }
...@@ -11,7 +11,7 @@ import "runtime" ...@@ -11,7 +11,7 @@ import "runtime"
func mk2() { func mk2() {
b := new([10000]byte) b := new([10000]byte)
_ = b _ = b
// println(b, "stored at", &b); // println(b, "stored at", &b)
} }
func mk1() { mk2() } func mk1() { mk2() }
......
...@@ -8,7 +8,7 @@ package main ...@@ -8,7 +8,7 @@ package main
func main() { func main() {
for i := 0; i < 1e5; i++ { for i := 0; i < 1e5; i++ {
x := new([100]byte); x := new([100]byte)
_ = x; _ = x
} }
} }
...@@ -11,7 +11,7 @@ package main ...@@ -11,7 +11,7 @@ package main
func ASSERT(p bool) { func ASSERT(p bool) {
if !p { if !p {
// panic 0; // panic 0
} }
} }
...@@ -20,7 +20,7 @@ func ASSERT(p bool) { ...@@ -20,7 +20,7 @@ func ASSERT(p bool) {
// Implementation of the HashMap // Implementation of the HashMap
type KeyType interface { type KeyType interface {
Hash() uint32; Hash() uint32
Match(other *KeyType) bool Match(other *KeyType) bool
} }
...@@ -31,31 +31,30 @@ type ValueType interface { ...@@ -31,31 +31,30 @@ type ValueType interface {
type Entry struct { type Entry struct {
key *KeyType; key *KeyType
value *ValueType; value *ValueType
} }
// Using the Array type below doesn't seem to work type Array [1024]Entry
//type Array array [1024] Entry;
type HashMap struct { type HashMap struct {
map_ *[1024] Entry; map_ *Array
log2_capacity_ uint32; log2_capacity_ uint32
occupancy_ uint32; occupancy_ uint32
} }
func (m *HashMap) capacity() uint32 { func (m *HashMap) capacity() uint32 {
return 1 << m.log2_capacity_; return 1 << m.log2_capacity_
} }
func (m *HashMap) Clear() { func (m *HashMap) Clear() {
// Mark all entries as empty. // Mark all entries as empty.
var i uint32 = m.capacity() - 1; var i uint32 = m.capacity() - 1
for i > 0 { for i > 0 {
m.map_[i].key = nil; m.map_[i].key = nil
i = i - 1 i = i - 1
} }
m.occupancy_ = 0 m.occupancy_ = 0
...@@ -63,72 +62,72 @@ func (m *HashMap) Clear() { ...@@ -63,72 +62,72 @@ func (m *HashMap) Clear() {
func (m *HashMap) Initialize (initial_log2_capacity uint32) { func (m *HashMap) Initialize (initial_log2_capacity uint32) {
m.log2_capacity_ = initial_log2_capacity; m.log2_capacity_ = initial_log2_capacity
m.map_ = new([1024] Entry); m.map_ = new(Array)
m.Clear(); m.Clear()
} }
func (m *HashMap) Probe (key *KeyType) *Entry { func (m *HashMap) Probe (key *KeyType) *Entry {
ASSERT(key != nil); ASSERT(key != nil)
var i uint32 = key.Hash() % m.capacity(); var i uint32 = key.Hash() % m.capacity()
ASSERT(0 <= i && i < 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) { for m.map_[i].key != nil && !m.map_[i].key.Match(key) {
i++; i++
if i >= m.capacity() { 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. // Find a matching entry.
var p *Entry = m.Probe(key); var p *Entry = m.Probe(key)
if p.key != nil { if p.key != nil {
return p; return p
} }
// No entry found; insert one if necessary. // No entry found; insert one if necessary.
if insert { if insert {
p.key = key; p.key = key
p.value = nil; p.value = nil
m.occupancy_++; m.occupancy_++
// Grow the map if we reached >= 80% occupancy. // Grow the map if we reached >= 80% occupancy.
if m.occupancy_ + m.occupancy_/4 >= m.capacity() { if m.occupancy_ + m.occupancy_/4 >= m.capacity() {
m.Resize(); m.Resize()
p = m.Probe(key); p = m.Probe(key)
} }
return p; return p
} }
// No entry found and none inserted. // No entry found and none inserted.
return nil; return nil
} }
func (m *HashMap) Resize() { func (m *HashMap) Resize() {
var hmap *[1024] Entry = m.map_; var hmap *Array = m.map_
var n uint32 = m.occupancy_; var n uint32 = m.occupancy_
// Allocate a new map of twice the current size. // 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. // Rehash all current entries.
var i uint32 = 0; var i uint32 = 0
for n > 0 { for n > 0 {
if hmap[i].key != nil { if hmap[i].key != nil {
m.Lookup(hmap[i].key, true).value = hmap[i].value; m.Lookup(hmap[i].key, true).value = hmap[i].value
n = n - 1; n = n - 1
} }
i++; i++
} }
} }
...@@ -137,46 +136,46 @@ func (m *HashMap) Resize() { ...@@ -137,46 +136,46 @@ func (m *HashMap) Resize() {
// Test code // Test code
type Number struct { type Number struct {
x uint32; x uint32
} }
func (n *Number) Hash() uint32 { func (n *Number) Hash() uint32 {
return n.x * 23; return n.x * 23
} }
func (n *Number) Match(other *KeyType) bool { func (n *Number) Match(other *KeyType) bool {
// var y *Number = other; // var y *Number = other
// return n.x == y.x; // return n.x == y.x
return false; return false
} }
func MakeNumber (x uint32) *Number { func MakeNumber (x uint32) *Number {
var n *Number = new(Number); var n *Number = new(Number)
n.x = x; n.x = x
return n; return n
} }
func main() { 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); var hmap *HashMap = new(HashMap)
hmap.Initialize(0); hmap.Initialize(0)
var x1 *Number = MakeNumber(1001); var x1 *Number = MakeNumber(1001)
var x2 *Number = MakeNumber(2002); var x2 *Number = MakeNumber(2002)
var x3 *Number = MakeNumber(3003); var x3 *Number = MakeNumber(3003)
_, _, _ = x1, x2, x3; _, _, _ = x1, x2, x3
// this doesn't work I think... // this doesn't work I think...
//hmap.Lookup(x1, true); //hmap.Lookup(x1, true)
//hmap.Lookup(x2, true); //hmap.Lookup(x2, true)
//hmap.Lookup(x3, true); //hmap.Lookup(x3, true)
//print "done\n"; //print "done\n"
} }
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
package main package main
func main() { func main() {
print("hello, world\n"); print("hello, world\n")
} }
...@@ -8,92 +8,92 @@ package main ...@@ -8,92 +8,92 @@ package main
func assertequal(is, shouldbe int, msg string) { func assertequal(is, shouldbe int, msg string) {
if is != shouldbe { if is != shouldbe {
print("assertion fail", msg, "\n"); print("assertion fail", msg, "\n")
panic(1); panic(1)
} }
} }
func main() { func main() {
i5 := 5; i5 := 5
i7 := 7; i7 := 7
var count int; var count int
count = 0; count = 0
if true { if true {
count = count + 1; count = count + 1
} }
assertequal(count, 1, "if true"); assertequal(count, 1, "if true")
count = 0; count = 0
if false { 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 { 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 { if one := 1; false {
count = count + 1; count = count + 1
_ = one; _ = one
} }
assertequal(count, 0, "if false one"); assertequal(count, 0, "if false one")
count = 0; count = 0
if { 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 { 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 { 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 { if true {
count = count + 1; count = count + 1
} else } else
count = count - 1; count = count - 1
assertequal(count, 1, "if else true"); assertequal(count, 1, "if else true")
count = 0; count = 0
if false { if false {
count = count + 1; count = count + 1
} else } else
count = count - 1; count = count - 1
assertequal(count, -1, "if else false"); assertequal(count, -1, "if else false")
count = 0; count = 0
if t:=1; false { if t:=1; false {
count = count + 1; count = count + 1
_ = t; _ = t
t := 7; t := 7
_ = t; _ = t
} else } else
count = count - t; count = count - t
assertequal(count, -1, "if else false var"); assertequal(count, -1, "if else false var")
count = 0; count = 0
t := 1; t := 1
if false { if false {
count = count + 1; count = count + 1
t := 7; t := 7
_ = t; _ = t
} else } else
count = count - t; count = count - t
_ = t; _ = t
assertequal(count, -1, "if else false var outside"); assertequal(count, -1, "if else false var outside")
} }
...@@ -9,12 +9,12 @@ package main ...@@ -9,12 +9,12 @@ package main
import "os" import "os"
func main() { func main() {
count := 7; count := 7
if one := 1; { if one := 1; {
count = count + one count = count + one
} }
if count != 8 { if count != 8 {
print(count, " should be 8\n"); print(count, " should be 8\n")
os.Exit(1) os.Exit(1)
} }
} }
...@@ -16,10 +16,10 @@ import . "os" ...@@ -16,10 +16,10 @@ import . "os"
func f(e os.Error) func f(e os.Error)
func main() { func main() {
var _e_ _os_.Error; var _e_ _os_.Error
var dot Error; var dot Error
f(_e_); f(_e_)
f(dot); f(dot)
} }
...@@ -12,6 +12,6 @@ import "bufio" // GCCGO_ERROR "previous|not used" ...@@ -12,6 +12,6 @@ import "bufio" // GCCGO_ERROR "previous|not used"
import bufio "os" // ERROR "redeclared|redefinition|incompatible" import bufio "os" // ERROR "redeclared|redefinition|incompatible"
import ( import (
"fmt"; // GCCGO_ERROR "previous|not used" "fmt" // GCCGO_ERROR "previous|not used"
fmt "math"; // ERROR "redeclared|redefinition|incompatible" fmt "math" // ERROR "redeclared|redefinition|incompatible"
) )
...@@ -64,5 +64,5 @@ func f() { ...@@ -64,5 +64,5 @@ func f() {
cap(b1)+ // ERROR "illegal|invalid|must be" cap(b1)+ // ERROR "illegal|invalid|must be"
cap(b2)+ // ERROR "illegal|invalid|must be" cap(b2)+ // ERROR "illegal|invalid|must be"
cap(b3)+ cap(b3)+
cap(b4); // ERROR "illegal|invalid|must be" cap(b4) // ERROR "illegal|invalid|must be"
} }
...@@ -10,11 +10,11 @@ import "fmt" ...@@ -10,11 +10,11 @@ import "fmt"
import "reflect" import "reflect"
type S struct { type S struct {
A, B, C, X, Y, Z int; A, B, C, X, Y, Z int
} }
type T struct { type T struct {
S; S
} }
var a1 = S { 0, 0, 0, 1, 2, 3 } var a1 = S { 0, 0, 0, 1, 2, 3 }
...@@ -49,14 +49,14 @@ var same = []Same { ...@@ -49,14 +49,14 @@ var same = []Same {
} }
func main() { func main() {
ok := true; ok := true
for _, s := range same { for _, s := range same {
if !reflect.DeepEqual(s.a, s.b) { if !reflect.DeepEqual(s.a, s.b) {
ok = false; ok = false
fmt.Printf("not same: %v and %v\n", s.a, s.b); fmt.Printf("not same: %v and %v\n", s.a, s.b)
} }
} }
if !ok { if !ok {
fmt.Println("BUG: test/initialize"); fmt.Println("BUG: test/initialize")
} }
} }
...@@ -7,17 +7,17 @@ ...@@ -7,17 +7,17 @@
package main package main
type S struct { type S struct {
A, B, C, X, Y, Z int; A, B, C, X, Y, Z int
} }
type T struct { type T struct {
S; S
} }
var x = 1 var x = 1
var a1 = S { 0, X: 1 }; // ERROR "mixture|undefined" var a1 = S { 0, X: 1 } // ERROR "mixture|undefined"
var a2 = S { Y: 3, Z: 2, Y: 3 }; // ERROR "duplicate" 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 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 a4 = [5]byte{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } // ERROR "index|too many"
var a5 = []byte { x: 2 } // ERROR "index" var a5 = []byte { x: 2 } // ERROR "index"
......
...@@ -18,8 +18,8 @@ func f() { ...@@ -18,8 +18,8 @@ func f() {
} }
func init() { func init() {
go f(); go f()
time.Nanoseconds(); time.Nanoseconds()
} }
func main() { func main() {
......
...@@ -16,9 +16,9 @@ func main() { ...@@ -16,9 +16,9 @@ func main() {
0x0 + 0x0 +
0x123 + 0x123 +
0X0 + 0X0 +
0X123; 0X123
if s != 788 { if s != 788 {
print("s is ", s, "; should be 788\n"); print("s is ", s, "; should be 788\n")
os.Exit(1); os.Exit(1)
} }
} }
...@@ -23,24 +23,24 @@ func (z *IntPtr) M() int64 { return int64(*z) } ...@@ -23,24 +23,24 @@ func (z *IntPtr) M() int64 { return int64(*z) }
var bad bool var bad bool
func test(name string, i I) { func test(name string, i I) {
m := i.M(); m := i.M()
if m != 12345 { if m != 12345 {
println(name, m); println(name, m)
bad = true; bad = true
} }
} }
func ptrs() { func ptrs() {
var bigptr BigPtr = BigPtr{ 10000, 2000, 300, 45 }; var bigptr BigPtr = BigPtr{ 10000, 2000, 300, 45 }
var smallptr SmallPtr = SmallPtr{ 12345 }; var smallptr SmallPtr = SmallPtr{ 12345 }
var intptr IntPtr = 12345; var intptr IntPtr = 12345
// test("bigptr", bigptr); // test("bigptr", bigptr)
test("&bigptr", &bigptr); test("&bigptr", &bigptr)
// test("smallptr", smallptr); // test("smallptr", smallptr)
test("&smallptr", &smallptr); test("&smallptr", &smallptr)
// test("intptr", intptr); // test("intptr", intptr)
test("&intptr", &intptr); test("&intptr", &intptr)
} }
type Big struct { a, b, c, d int64 } type Big struct { a, b, c, d int64 }
...@@ -53,23 +53,23 @@ type Int int32 ...@@ -53,23 +53,23 @@ type Int int32
func (z Int) M() int64 { return int64(z) } func (z Int) M() int64 { return int64(z) }
func nonptrs() { func nonptrs() {
var big Big = Big{ 10000, 2000, 300, 45 }; var big Big = Big{ 10000, 2000, 300, 45 }
var small Small = Small{ 12345 }; var small Small = Small{ 12345 }
var int Int = 12345; var int Int = 12345
test("big", big); test("big", big)
test("&big", &big); test("&big", &big)
test("small", small); test("small", small)
test("&small", &small); test("&small", &small)
test("int", int); test("int", int)
test("&int", &int); test("&int", &int)
} }
func main() { func main() {
ptrs(); ptrs()
nonptrs(); nonptrs()
if bad { if bad {
println("BUG: interface4"); println("BUG: interface4")
} }
} }
...@@ -9,17 +9,17 @@ ...@@ -9,17 +9,17 @@
package main package main
type R interface { R(); } type R interface { R() }
type RW interface { R(); W(); } type RW interface { R(); W() }
var e interface {} var e interface {}
var r R; var r R
var rw RW; var rw RW
func main() { func main() {
r = r; r = r
r = rw; r = rw
e = r; e = r
e = rw; e = rw
rw = rw; rw = rw
} }
...@@ -9,17 +9,17 @@ ...@@ -9,17 +9,17 @@
package main package main
type R interface { R(); } type R interface { R() }
type RW interface { R(); W(); } type RW interface { R(); W() }
var e interface {} var e interface {}
var r R; var r R
var rw RW; var rw RW
func main() { func main() {
r = r; r = r
r = rw; r = rw
e = r; e = r
e = rw; e = rw
rw = rw; rw = rw
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -18,8 +18,8 @@ type I1 interface { Name() int8 } ...@@ -18,8 +18,8 @@ type I1 interface { Name() int8 }
type I2 interface { Name() int64 } type I2 interface { Name() int64 }
func main() { func main() {
var i1 I1; var i1 I1
var s *S; var s *S
i1 = s; i1 = s
print(i1.(I2).Name()) print(i1.(I2).Name())
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment