1
0
mirror of https://github.com/golang/go synced 2024-11-21 19:34:46 -07:00

fix "declared and not used" in tests;

also template/template.go, missed last time.

R=r
DELTA=116  (61 added, 10 deleted, 45 changed)
OCL=34620
CL=34622
This commit is contained in:
Russ Cox 2009-09-14 21:03:53 -07:00
parent 59914723df
commit 1a3198907b
57 changed files with 128 additions and 77 deletions

View File

@ -397,12 +397,12 @@ func (t *Template) newVariable(name_formatter string) (v *variableElement) {
// Is it in user-supplied map?
if t.fmap != nil {
if fn, ok := t.fmap[formatter]; ok {
if _, ok := t.fmap[formatter]; ok {
return
}
}
// Is it in builtin map?
if fn, ok := builtins[formatter]; ok {
if _, ok := builtins[formatter]; ok {
return
}
t.parseError("unknown formatter: %s", formatter);
@ -631,17 +631,17 @@ func (t *Template) writeVariable(v *variableElement, st *state) {
val := t.varValue(v.name, st).Interface();
// is it in user-supplied map?
if t.fmap != nil {
if fn, ok := t.fmap[v.formatter]; ok {
fn(st.wr, val, v.formatter);
if fn, ok := t.fmap[formatter]; ok {
fn(st.wr, val, formatter);
return;
}
}
// is it in builtin map?
if fn, ok := builtins[v.formatter]; ok {
fn(st.wr, val, v.formatter);
if fn, ok := builtins[formatter]; ok {
fn(st.wr, val, formatter);
return;
}
t.execError(st, v.linenum, "missing formatter %s for variable %s", v.formatter, v.name)
t.execError(st, v.linenum, "missing formatter %s for variable %s", formatter, v.name)
}
// Execute element i. Return next index to execute.
@ -796,7 +796,7 @@ func validDelim(d []byte) bool {
if len(d) == 0 {
return false
}
for i, c := range d {
for _, c := range d {
if white(c) {
return false
}

View File

@ -53,7 +53,6 @@ func main() {
}
for i := 0; i < len(OUT); i++ {
t := min(xs);
for i := 0; i < n; i++ {
ins[i] <- x;
}

View File

@ -22,7 +22,6 @@ var a = []int{ 1, 2, 3 }
var NIL []int;
func arraycmptest() {
a1 := a;
if NIL != nil {
println("fail1:", NIL, "!= nil");
}
@ -112,6 +111,7 @@ func interfacetest() {
i = e;
e1 := i.(E);
// nothing to check; just verify it doesn't crash
_ = e1;
}
func main() {

View File

@ -26,6 +26,8 @@ func xxx() {
xx, ok = i.(int);
a,b := multi();
_, _, _, _, _ = x, ok, xx, a, b;
}
func f() map[int]int {

View File

@ -46,7 +46,7 @@ func main() {
oai = []int{1,2,3};
if len(oai) != 3 { panic("oai") }
at := [...]*T{&t, &t, &t};
at := [...]*T{&t, tp, &t};
if len(at) != 3 { panic("at") }
c := make(chan int);

View File

@ -30,8 +30,10 @@ func main() {
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");
}
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h;
}

View File

@ -10,9 +10,9 @@ func main() {
i5 := 5;
switch { // compiler crash fixable with 'switch true'
case i5 < 5: dummy := 0;
case i5 == 5: dummy := 0;
case i5 > 5: dummy := 0;
case i5 < 5: dummy := 0; _ = dummy;
case i5 == 5: dummy := 0; _ = dummy;
case i5 > 5: dummy := 0; _ = dummy;
}
}
/*

View File

@ -8,7 +8,7 @@ package main
func main() {
fired := false;
fired := false; _ = fired;
}
/*
bug9.go:5: defaultlit: unknown literal: LITERAL-B0 a(1)

View File

@ -20,6 +20,7 @@ func main() {
t.x = 1;
t.y = 2;
r10 := t.m(1, 3.0);
_ = r10;
}
/*
bug11.go:16: fatal error: walktype: switch 1 unknown op CALLMETH l(16) <int32>INT32

View File

@ -10,6 +10,7 @@ package main
func main() {
var u30 uint64 = 0;
var u31 uint64 = 1;
_, _ = u30, u31;
var u32 uint64 = 18446744073709551615;
var u33 uint64 = +18446744073709551615;
if u32 != (1<<64)-1 { panic("u32\n"); }

View File

@ -9,6 +9,7 @@ package main
func main() {
var cu0 uint16 = '\u1234';
var cU1 uint32 = '\U00101234';
_, _ = cu0, cU1;
}
/*
bug13.go:4: missing '

View File

@ -8,6 +8,7 @@ package main
func main() {
var s2 string = "\a\b\f\n\r\t\v"; // \r is miscompiled
_ = s2;
}
/*
main.go.c: In function main_main:

View File

@ -22,6 +22,7 @@ func (i *TInt) TypeName() string {
func main() {
var t Type;
t = nil;
_ = t;
}
/*

View File

@ -12,6 +12,7 @@ func main() {
i = '\\';
var s string;
s = "\"";
_, _ = i, s;
}
/*
bug.go:5: unknown escape sequence: '

View File

@ -23,6 +23,7 @@ prog := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"+
"xxxxxxxx"+
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
;
_ = prog;
}
/* Segmentation fault */

View File

@ -8,4 +8,5 @@ package main
func main() {
var len int; // len should not be a keyword - this doesn't compile
_ = len;
}

View File

@ -17,5 +17,6 @@ func main() {
i = 0;
type s2 int;
var k = func (a int) int { return a+1 }(3);
_, _ = j, k;
ro:
}

View File

@ -16,6 +16,7 @@ func main() {
l1 := len(s);
var t T;
l2 := len(t.s); // BUG: cannot take len() of a string field
_, _ = l1, l2;
}
/*

View File

@ -9,6 +9,7 @@ package main
func main() {
var s string;
s = "0000000000000000000000000000000000000000000000000000000000"[0:7];
_ = s;
}
/*

View File

@ -9,10 +9,12 @@ package main
func main(){
c := make(chan int);
ok := false;
i := 0;
var i int;
i, ok = <-c; // works
_, _ = i, ok;
ca := new([2]chan int);
i, ok = <-(ca[0]); // fails: c.go:11: bad shape across assignment - cr=1 cl=2
_, _ = i, ok;
}

View File

@ -7,7 +7,7 @@
package main
func main() {
var i, j, k int;
var i, k int;
outer:
for k=0; k<2; k++ {
print("outer loop top k ", k, "\n");

View File

@ -19,4 +19,5 @@ type dch struct {
func dosplit(in *dch){
dat := <-in.dat;
_ = dat;
}

View File

@ -13,4 +13,5 @@ func main() {
var x int;
var ok bool;
x, ok = t.m[0]; //bug075.go:11: bad shape across assignment - cr=1 cl=2
_, _ = x, ok;
}

View File

@ -9,4 +9,5 @@ package main
func main() {
var exit int;
exit:
_ = exit;
}

View File

@ -20,4 +20,5 @@ func main() {
c := make(chan string);
a := new(Service);
go a.Serve(1234);
_ = c;
}

View File

@ -10,6 +10,7 @@ const s string = "foo";
func main() {
i := len(s); // should be legal to take len() of a constant
_ = i;
}
/*

View File

@ -10,6 +10,7 @@ func main() {
a0 := P.V0(); // works
a1 := P.V1(); // works
a2, b2 := P.V2(); // doesn't work
_, _, _, _ = a0, a1, a2, b2;
}
/*

View File

@ -9,6 +9,7 @@ package main
func main() {
var a [1000] int64; // this alone works
var b [10000] int64; // this causes a runtime crash
_, _ = a, b;
}
/*

View File

@ -13,6 +13,7 @@ func f0() {
func f1() {
x := 0;
_ = x;
}

View File

@ -11,6 +11,7 @@ type A []int;
func main() {
a := &A{0};
b := &A{0, 1};
_, _ = a, b;
}
/*

View File

@ -12,6 +12,7 @@ type M map[int] int;
func main() {
var a *A = &A{0};
var m *M = &M{0 : 0}; // should be legal to use & here for consistency with other composite constructors (prev. line)
_, _ = a, m;
}
/*

View File

@ -7,5 +7,6 @@
package foo
import "fmt"
func f() {
fmt := 1
fmt := 1;
_ = fmt;
}

View File

@ -15,4 +15,5 @@ func main() {
t := new(T);
var i interface {};
f, ok := i.(Foo);
_, _, _ = t, f, ok;
}

View File

@ -29,7 +29,8 @@ func main() {
{
var x int;
var ok bool;
x, ok = f()["key"]
x, ok = f()["key"];
_, _ = x, ok;
}
}

View File

@ -10,6 +10,7 @@ const c = 1;
func main() {
c := 0;
_ = c;
}
/*

View File

@ -9,7 +9,8 @@ package main
type t int
func main() {
t := 0
t := 0;
_ = t;
}
/*

View File

@ -17,6 +17,7 @@ func f0() string {
func f1() string {
const f = 3.141592;
x := float64(float32(f)); // appears to change the precision of f
_ = x;
return fmt.Sprintf("%v", float64(f));
}

View File

@ -17,6 +17,7 @@ L:
L1:
x := 1;
_ = x;
for {
break L1; // ERROR "L1"
continue L1; // ERROR "L1"

View File

@ -12,7 +12,6 @@ func main() {
// This bug doesn't arise with [...]int, or []interface{} or [3]interface{}.
a := [...]interface{} { 1, 2, 3 };
n := 1;
bug := false;
for _, v := range a {
if v.(int) != n {
println("BUG:", n, v.(int));

View File

@ -6,11 +6,11 @@
package main
func f() {
v := [...]string{"a", "b"};
v := [...]string{"a", "b"};
_ = v;
}
func main() {
f();
}

View File

@ -10,6 +10,7 @@ import "malloc"
func mk2() {
b := new([10000]byte);
_ = b;
// println(b, "stored at", &b);
}

View File

@ -9,5 +9,6 @@ package main
func main() {
for i := 0; i < 1000000; i++ {
x := new([100]byte);
_ = x;
}
}

View File

@ -171,6 +171,7 @@ func main() {
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);

View File

@ -40,6 +40,7 @@ func main() {
count = 0;
if one := 1; false {
count = count + 1;
_ = one;
}
assertequal(count, 0, "if false one");
@ -78,7 +79,9 @@ func main() {
count = 0;
if t:=1; false {
count = count + 1;
_ = t;
t := 7;
_ = t;
} else
count = count - t;
assertequal(count, -1, "if else false var");
@ -88,7 +91,9 @@ func main() {
if false {
count = count + 1;
t := 7;
_ = t;
} else
count = count - t;
_ = t;
assertequal(count, -1, "if else false var outside");
}

View File

@ -102,8 +102,7 @@ func main() {
hello(t.String());
// I2T2 false
var u1 U;
u1, ok = s.(U);
_, ok = s.(U);
false(ok);
// I2I2 true

View File

@ -18,6 +18,7 @@ func main() {
var e interface {};
e = s;
i = e.(I);
_ = i;
}
// hide S down here to avoid static warning

View File

@ -30,7 +30,6 @@ func AddInst(Inst) *Inst {
}
func main() {
re := new(Regexp);
print("call addinst\n");
var x Inst = AddInst(new(Start)); // ERROR "illegal|incompatible|is not"
print("return from addinst\n");

View File

@ -27,17 +27,23 @@ func main() {
v = t;
p = t; // ERROR "is not|requires a pointer"
_, _= v, p;
v = &t;
p = &t;
_, _= v, p;
v = s;
p = s; // ERROR "is not|requires a pointer"
_, _= v, p;
v = &s;
p = &s;
_, _= v, p;
v = sp;
p = sp; // no error!
_, _= v, p;
v = &sp;
p = &sp;
_, _= v, p;
}

View File

@ -149,7 +149,6 @@ func WhiteSpace(c int) bool
func NextToken()
{
var i, c int;
var backslash bool;
tokenbuf[0] = nilchar; // clear previous token
c = Get();
@ -222,8 +221,7 @@ func ParseList() *Slist
func atom(i int) *Slist // BUG: uses tokenbuf; should take argument
{
var h, length int;
var slist, tail *Slist;
var slist *Slist;
slist = new(Slist);
if token == '0' {

View File

@ -39,6 +39,7 @@ func main() {
count = 0;
if one := 1; false {
_ = one;
count = count + 1;
}
assertequal(count, 0, "if false one");
@ -79,6 +80,7 @@ func main() {
if t:=1; false {
count = count + 1;
t := 7;
_ = t;
} else
count = count - t;
assertequal(count, -1, "if else false var");
@ -88,6 +90,7 @@ func main() {
if false {
count = count + 1;
t := 7;
_ = t;
} else
count = count - t;
assertequal(count, -1, "if else false var outside");

View File

@ -19,6 +19,7 @@ main()
var x int;
x = 25;
y = 25;
_ = x;
}
x = x+y;
if(x != 40) { panic(x); }

View File

@ -108,6 +108,7 @@ func main() {
var u31 uint64 = 1;
var u32 uint64 = 18446744073709551615;
var u33 uint64 = +18446744073709551615;
_, _, _, _ = u30, u31, u32, u33;
// float
var f00 float = 3.14159;
@ -192,6 +193,7 @@ func main() {
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";

View File

@ -33,7 +33,6 @@ func main() {
var ps *S1;
var i I;
var pi *I1;
var t T;
var pt *T1;
if s.val() != 1 { panicln("s.val:", s.val()) }

View File

@ -32,4 +32,6 @@ func main() {
i = nil;
ta = make([]IN, 1);
ta[0] = nil;
_, _, _, _, _, _, _, _ = i, f, s, m, c, t, in, ta;
}

View File

@ -15,7 +15,6 @@ import (
func main() {
s := "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe\U0010FFFFx";
expect := []int{ 0, 0123, 0, 0xFFFD, 0xFFFD, 0x123, 0xbabe, 0xbabe, 0x10FFFF, 'x' };
var rune, size int;
offset := 0;
var i, c int;
ok := true;

View File

@ -78,32 +78,32 @@ func main() {
}
switch i5 {
case 0: dummy := 0; fallthrough;
case 1: dummy := 0; fallthrough;
case 2: dummy := 0; fallthrough;
case 3: dummy := 0; fallthrough;
case 4: dummy := 0; assert(false, "4");
case 5: dummy := 0; fallthrough;
case 6: dummy := 0; fallthrough;
case 7: dummy := 0; fallthrough;
case 8: dummy := 0; fallthrough;
case 9: dummy := 0; fallthrough;
default: dummy := 0; 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;
switch i5 {
case 0: dummy := 0; fallthrough; // tests scoping of cases
case 1: dummy := 0; fallthrough;
case 2: dummy := 0; fallthrough;
case 3: dummy := 0; fallthrough;
case 4: dummy := 0; assert(false, "4");
case 5: dummy := 0; fallthrough;
case 6: dummy := 0; fallthrough;
case 7: dummy := 0; fallthrough;
case 8: dummy := 0; fallthrough;
case 9: dummy := 0; fallthrough;
default: dummy := 0; fired = !fired; assert(i5 == 5, "good");
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");
}
assert(fired, "fired");

View File

@ -58,12 +58,14 @@ func control_structs() {
var p *Point = new(Point).Initialize(2, 3);
i := p.Distance();
var f float = 0.3;
_ = f;
for {}
for {};
for j := 0; j < i; j++ {
if i == 0 {
} else i = 0;
var x float;
_ = x;
}
foo: // a label
var j int;