2012-02-16 21:49:30 -07:00
|
|
|
// errorcheck
|
2008-08-13 13:15:24 -06:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
const (
|
|
|
|
c3div2 = 3/2;
|
|
|
|
f3div2 = 3./2.;
|
|
|
|
)
|
|
|
|
|
|
|
|
func assert(t bool, s string) {
|
|
|
|
if !t {
|
|
|
|
panic(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var i int;
|
|
|
|
var f float64;
|
|
|
|
|
|
|
|
assert(c3div2 == 1, "3/2");
|
|
|
|
assert(f3div2 == 1.5, "3/2");
|
|
|
|
|
|
|
|
i = c3div2;
|
|
|
|
assert(i == c3div2, "i == c3div2");
|
|
|
|
|
|
|
|
f = c3div2;
|
|
|
|
assert(f == c3div2, "f == c3div2");
|
|
|
|
|
|
|
|
f = f3div2;
|
|
|
|
assert(f == f3div2, "f == f3div2");
|
|
|
|
|
2009-03-12 20:04:38 -06:00
|
|
|
i = f3div2; // ERROR "truncate"
|
2008-08-13 13:15:24 -06:00
|
|
|
assert(i == c3div2, "i == c3div2 from f3div2");
|
2009-03-12 20:04:38 -06:00
|
|
|
assert(i != f3div2, "i != f3div2"); // ERROR "truncate"
|
2008-08-20 16:43:12 -06:00
|
|
|
|
|
|
|
const g float64 = 1.0;
|
2009-08-03 12:58:52 -06:00
|
|
|
i = g; // ERROR "convert|incompatible|cannot"
|
2008-08-20 16:43:12 -06:00
|
|
|
|
|
|
|
const h float64 = 3.14;
|
2009-08-03 12:58:52 -06:00
|
|
|
i = h; // ERROR "convert|incompatible|cannot"
|
2009-03-12 20:04:38 -06:00
|
|
|
i = int(h); // ERROR "truncate"
|
2008-08-13 13:15:24 -06:00
|
|
|
}
|