Commit 1a319890 authored by Russ Cox's avatar Russ Cox

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
parent 59914723
......@@ -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
}
......
......@@ -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;
}
......
......@@ -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() {
......
......@@ -26,6 +26,8 @@ func xxx() {
xx, ok = i.(int);
a,b := multi();
_, _, _, _, _ = x, ok, xx, a, b;
}
func f() map[int]int {
......
......@@ -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);
......
......@@ -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;
}
......@@ -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;
}
}
/*
......
......@@ -8,7 +8,7 @@ package main
func main() {
fired := false;
fired := false; _ = fired;
}
/*
bug9.go:5: defaultlit: unknown literal: LITERAL-B0 a(1)
......
......@@ -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
......
......@@ -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"); }
......
......@@ -9,6 +9,7 @@ package main
func main() {
var cu0 uint16 = '\u1234';
var cU1 uint32 = '\U00101234';
_, _ = cu0, cU1;
}
/*
bug13.go:4: missing '
......
......@@ -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’:
......
......@@ -22,6 +22,7 @@ func (i *TInt) TypeName() string {
func main() {
var t Type;
t = nil;
_ = t;
}
/*
......
......@@ -12,6 +12,7 @@ func main() {
i = '\\';
var s string;
s = "\"";
_, _ = i, s;
}
/*
bug.go:5: unknown escape sequence: '
......
......@@ -23,6 +23,7 @@ prog := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"+
"xxxxxxxx"+
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
;
_ = prog;
}
/* Segmentation fault */
......@@ -8,4 +8,5 @@ package main
func main() {
var len int; // len should not be a keyword - this doesn't compile
_ = len;
}
......@@ -17,5 +17,6 @@ func main() {
i = 0;
type s2 int;
var k = func (a int) int { return a+1 }(3);
_, _ = j, k;
ro:
}
......@@ -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;
}
/*
......
......@@ -9,6 +9,7 @@ package main
func main() {
var s string;
s = "0000000000000000000000000000000000000000000000000000000000"[0:7];
_ = s;
}
/*
......
......@@ -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;
}
......@@ -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");
......
......@@ -19,4 +19,5 @@ type dch struct {
func dosplit(in *dch){
dat := <-in.dat;
_ = dat;
}
......@@ -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;
}
......@@ -9,4 +9,5 @@ package main
func main() {
var exit int;
exit:
_ = exit;
}
......@@ -20,4 +20,5 @@ func main() {
c := make(chan string);
a := new(Service);
go a.Serve(1234);
_ = c;
}
......@@ -10,6 +10,7 @@ const s string = "foo";
func main() {
i := len(s); // should be legal to take len() of a constant
_ = i;
}
/*
......
......@@ -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;
}
/*
......
......@@ -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;
}
/*
......
......@@ -13,6 +13,7 @@ func f0() {
func f1() {
x := 0;
_ = x;
}
......@@ -27,5 +28,5 @@ bug094.go:11: left side of := must be a name
bad top
. LITERAL-I0 l(343)
bug094.go:11: fatal error: walktype: top=3 LITERAL
uetli:~/Source/go1/test/bugs gri$
uetli:~/Source/go1/test/bugs gri$
*/
......@@ -11,6 +11,7 @@ type A []int;
func main() {
a := &A{0};
b := &A{0, 1};
_, _ = a, b;
}
/*
......
......@@ -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;
}
/*
......
......@@ -7,5 +7,6 @@
package foo
import "fmt"
func f() {
fmt := 1
fmt := 1;
_ = fmt;
}
......@@ -15,4 +15,5 @@ func main() {
t := new(T);
var i interface {};
f, ok := i.(Foo);
_, _, _ = t, f, ok;
}
......@@ -29,7 +29,8 @@ func main() {
{
var x int;
var ok bool;
x, ok = f()["key"]
x, ok = f()["key"];
_, _ = x, ok;
}
}
......
......@@ -10,6 +10,7 @@ const c = 1;
func main() {
c := 0;
_ = c;
}
/*
......
......@@ -9,7 +9,8 @@ package main
type t int
func main() {
t := 0
t := 0;
_ = t;
}
/*
......
......@@ -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));
}
......
......@@ -17,6 +17,7 @@ L:
L1:
x := 1;
_ = x;
for {
break L1; // ERROR "L1"
continue L1; // ERROR "L1"
......
......@@ -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));
......
......@@ -6,11 +6,11 @@
package main
func f() {
v := [...]string{"a", "b"};
v := [...]string{"a", "b"};
_ = v;
}
func main() {
f();
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ import "malloc"
func mk2() {
b := new([10000]byte);
_ = b;
// println(b, "stored at", &b);
}
......
......@@ -9,5 +9,6 @@ package main
func main() {
for i := 0; i < 1000000; i++ {
x := new([100]byte);
_ = x;
}
}
......@@ -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);
......
......@@ -21,56 +21,57 @@ func main() {
count = 0;
if true {
count = count + 1;
count = count + 1;
}
assertequal(count, 1, "if true");
count = 0;
if false {
count = count + 1;
count = count + 1;
}
assertequal(count, 0, "if false");
count = 0;
if one := 1; true {
count = count + one;
count = count + one;
}
assertequal(count, 1, "if true one");
count = 0;
if one := 1; false {
count = count + 1;
count = count + 1;
_ = one;
}
assertequal(count, 0, "if false one");
count = 0;
if {
count = count + 1;
count = count + 1;
}
assertequal(count, 1, "if empty");
count = 0;
if one := 1; true {
count = count + one;
count = count + one;
}
assertequal(count, 1, "if empty one");
count = 0;
if i5 < i7 {
count = count + 1;
count = count + 1;
}
assertequal(count, 1, "if cond");
count = 0;
if true {
count = count + 1;
count = count + 1;
} else
count = count - 1;
assertequal(count, 1, "if else true");
count = 0;
if false {
count = count + 1;
count = count + 1;
} else
count = count - 1;
assertequal(count, -1, "if else false");
......@@ -78,7 +79,9 @@ func main() {
count = 0;
if t:=1; false {
count = count + 1;
t := 7;
_ = t;
t := 7;
_ = t;
} else
count = count - t;
assertequal(count, -1, "if else false var");
......@@ -87,8 +90,10 @@ func main() {
t := 1;
if false {
count = count + 1;
t := 7;
t := 7;
_ = t;
} else
count = count - t;
_ = t;
assertequal(count, -1, "if else false var outside");
}
......@@ -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
......
......@@ -18,6 +18,7 @@ func main() {
var e interface {};
e = s;
i = e.(I);
_ = i;
}
// hide S down here to avoid static warning
......
......@@ -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");
......
......@@ -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;
}
......@@ -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' {
......
......@@ -21,56 +21,57 @@ func main() {
count = 0;
if true {
count = count + 1;
count = count + 1;
}
assertequal(count, 1, "if true");
count = 0;
if false {
count = count + 1;
count = count + 1;
}
assertequal(count, 0, "if false");
count = 0;
if one := 1; true {
count = count + one;
count = count + one;
}
assertequal(count, 1, "if true one");
count = 0;
if one := 1; false {
count = count + 1;
_ = one;
count = count + 1;
}
assertequal(count, 0, "if false one");
count = 0;
if {
count = count + 1;
count = count + 1;
}
assertequal(count, 1, "if empty");
count = 0;
if one := 1; {
count = count + one;
count = count + one;
}
assertequal(count, 1, "if empty one");
count = 0;
if i5 < i7 {
count = count + 1;
count = count + 1;
}
assertequal(count, 1, "if cond");
count = 0;
if true {
count = count + 1;
count = count + 1;
} else
count = count - 1;
assertequal(count, 1, "if else true");
count = 0;
if false {
count = count + 1;
count = count + 1;
} else
count = count - 1;
assertequal(count, -1, "if else false");
......@@ -78,7 +79,8 @@ func main() {
count = 0;
if t:=1; false {
count = count + 1;
t := 7;
t := 7;
_ = t;
} else
count = count - t;
assertequal(count, -1, "if else false var");
......@@ -87,7 +89,8 @@ func main() {
t := 1;
if false {
count = count + 1;
t := 7;
t := 7;
_ = t;
} else
count = count - t;
assertequal(count, -1, "if else false var outside");
......
......@@ -19,6 +19,7 @@ main()
var x int;
x = 25;
y = 25;
_ = x;
}
x = x+y;
if(x != 40) { panic(x); }
......
......@@ -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";
......
......@@ -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()) }
......
......@@ -32,4 +32,6 @@ func main() {
i = nil;
ta = make([]IN, 1);
ta[0] = nil;
_, _, _, _, _, _, _, _ = i, f, s, m, c, t, in, ta;
}
......@@ -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;
......
......@@ -73,37 +73,37 @@ func main() {
case 6:
case 7:
case 8:
case 9:
case 9:
default: assert(i5 == 5, "good");
}
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");
......
......@@ -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;
......
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