diff options
author | Russ Cox <rsc@golang.org> | 2008-10-16 15:59:31 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2008-10-16 15:59:31 -0700 |
commit | e4def2f9594a39d1cd00a5e72bffe7b9df4a45e0 (patch) | |
tree | e0a34202934220fbb1b8af43881269f95e53121e /test | |
parent | e165c282e7d7077fa59e60481408f9b401a05e10 (diff) | |
download | go-e4def2f9594a39d1cd00a5e72bffe7b9df4a45e0.tar.gz |
diagnose various conversion problems
R=ken
OCL=17320
CL=17320
Diffstat (limited to 'test')
-rw-r--r-- | test/convlit.go | 35 | ||||
-rw-r--r-- | test/convlit1.go | 15 | ||||
-rwxr-xr-x | test/errchk | 2 | ||||
-rw-r--r-- | test/golden.out | 44 |
4 files changed, 86 insertions, 10 deletions
diff --git a/test/convlit.go b/test/convlit.go new file mode 100644 index 000000000..b6f3134c6 --- /dev/null +++ b/test/convlit.go @@ -0,0 +1,35 @@ +// errchk $G -e $D/$F.go + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// explicit conversions are okay, even if they overflow +var x1 = string(1); +var x2 string = string(1); +var x3 = int(1.5); +var x4 int = int(1.5); +var x5 = "a" + string(1); +var x6 = int(1e100); +var x7 = float(1e1000); + +// implicit conversions merit scrutiny +var s string; +var bad1 string = 1; // ERROR "conver" +var bad2 = s + 1; // ERROR "conver" +var bad3 = s + 'a'; // ERROR "conver" +var bad4 = "a" + 1; // ERROR "literals" +var bad5 = "a" + 'a'; // ERROR "literals" + +var bad6 int = 1.5; // ERROR "convert" +var bad7 int = 1e100; // ERROR "overflow" +var bad8 float = 1e1000; // ERROR "overflow" + +// but these implicit conversions are okay +var good1 string = "a"; +var good2 int = 1.0; +var good3 int = 1e9; +var good4 float = 1e20; + diff --git a/test/convlit1.go b/test/convlit1.go new file mode 100644 index 000000000..c15bfcb4b --- /dev/null +++ b/test/convlit1.go @@ -0,0 +1,15 @@ +// errchk $G $D/$F.go + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var a = []int { "a" }; // ERROR "conver" +var b = int { 1 }; // ERROR "compos" + + +func main() { + if sys.argc < 1 { } // ERROR "conver" +} diff --git a/test/errchk b/test/errchk index 2b27b851c..61b77e39d 100755 --- a/test/errchk +++ b/test/errchk @@ -41,7 +41,7 @@ if $* >$TMPOUT 2>$TMPERR; then exit 1 fi -cat $TMPOUT $TMPERR > $TMPALL +cat $TMPOUT $TMPERR | grep -v '^ ' > $TMPALL header=0 echo 0 > $TMPSTAT diff --git a/test/golden.out b/test/golden.out index 08479d408..230a451fd 100644 --- a/test/golden.out +++ b/test/golden.out @@ -1,4 +1,23 @@ +=========== ./convlit.go +BUG: convlit.go fails +BUG: errchk: ./convlit.go: missing expected error message on line 16: 'conver' +BUG: errchk: ./convlit.go: missing expected error message on line 17: 'conver' +BUG: errchk: ./convlit.go: missing expected error message on line 18: 'conver' +BUG: errchk: ./convlit.go: missing expected error message on line 22: 'convert' +BUG: errchk: ./convlit.go: missing expected error message on line 23: 'overflow' +BUG: errchk: ./convlit.go: missing expected error message on line 24: 'overflow' +BUG: errchk: ./convlit.go: unmatched error messages: +================================================== +./convlit.go:8: cannot convert non-integer constant to int32 +./convlit.go:11: overflow converting constant to int32 +./convlit.go:12: overflow converting constant to float32 +./convlit.go:8: cannot convert non-integer constant to int32 +./convlit.go:9: cannot convert non-integer constant to int32 +./convlit.go:11: overflow converting constant to int32 +./convlit.go:12: overflow converting constant to float32 +================================================== + =========== ./helloworld.go hello, world @@ -106,7 +125,16 @@ bugs/bug087.go:8: illegal combination of literals LEN 9 BUG: fails incorrectly =========== bugs/bug090.go -BUG: compilation succeeds incorrectly +bugs/bug090.go:32: cannot convert non-integer constant to int32 +bugs/bug090.go:32: illegal types for operand: AS + int32 +bugs/bug090.go:34: cannot convert non-integer constant to int32 +bugs/bug090.go:34: illegal types for operand: CALL + bool +bugs/bug090.go:40: cannot convert non-integer constant to int32 +bugs/bug090.go:40: illegal types for operand: AS + int32 + float64 =========== bugs/bug093.go M @@ -181,14 +209,15 @@ fixedbugs/bug035.go:7: var f redeclared in this block =========== fixedbugs/bug037.go fixedbugs/bug037.go:6: vlong: undefined -fixedbugs/bug037.go:6: fatal error: addvar: n=NAME-s G0 a(1) l(77) t=<T> nil +fixedbugs/bug037.go:6: illegal types for operand: AS + undefined =========== fixedbugs/bug039.go fixedbugs/bug039.go:6: var x redeclared in this block previous declaration at fixedbugs/bug039.go:5 =========== fixedbugs/bug049.go -fixedbugs/bug049.go:6: illegal conversion of constant to string +fixedbugs/bug049.go:6: illegal conversion of nil to string =========== fixedbugs/bug050.go fixedbugs/bug050.go:3: package statement must be first @@ -198,7 +227,7 @@ sys.6:1 fixedbugs/bug050.go:3: syntax error near package fixedbugs/bug051.go:10: expression must be a constant =========== fixedbugs/bug062.go -fixedbugs/bug062.go:6: illegal conversion of constant to string +fixedbugs/bug062.go:6: illegal conversion of nil to string fixedbugs/bug062.go:6: illegal types for operand: AS string @@ -216,10 +245,6 @@ broke =========== fixedbugs/bug072.go fixedbugs/bug072.go:6: bug: undefined -fixedbugs/bug072.go:6: illegal types for operand: CONV - string -fixedbugs/bug072.go:6: illegal types for operand: CONV - string =========== fixedbugs/bug073.go fixedbugs/bug073.go:8: illegal types for operand: LSH @@ -237,7 +262,8 @@ fixedbugs/bug086.go:5: function ends without a return statement =========== fixedbugs/bug091.go fixedbugs/bug091.go:15: c: undefined -fixedbugs/bug091.go:15: fatal error: addvar: n=NAME-i G0 a(1) l(86) t=<T> nil +fixedbugs/bug091.go:15: illegal types for operand: AS + undefined =========== fixedbugs/bug103.go fixedbugs/bug103.go:8: function requires a return type |