Source file test/fixedbugs/bug090.go

     1  // errorcheck
     2  
     3  // Copyright 2009 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  const (
    10  	c3div2 = 3/2;
    11  	f3div2 = 3./2.;
    12  )
    13  
    14  func assert(t bool, s string) {
    15  	if !t {
    16  		panic(s)
    17  	}
    18  }
    19  
    20  func main() {
    21  	var i int;
    22  	var f float64;
    23  
    24  	assert(c3div2 == 1, "3/2");
    25  	assert(f3div2 == 1.5, "3/2");
    26  
    27  	i = c3div2;
    28  	assert(i == c3div2, "i == c3div2");
    29  
    30  	f = c3div2;
    31  	assert(f == c3div2, "f == c3div2");
    32  
    33  	f = f3div2;
    34  	assert(f == f3div2, "f == f3div2");
    35  
    36  	i = f3div2;	// ERROR "truncate"
    37  	assert(i == c3div2, "i == c3div2 from f3div2");
    38  	assert(i != f3div2, "i != f3div2");	// ERROR "truncate"
    39  
    40  	const g float64 = 1.0;
    41  	i = g;  // ERROR "convert|incompatible|cannot"
    42  
    43  	const h float64 = 3.14;
    44  	i = h;  // ERROR "convert|incompatible|cannot"
    45  	i = int(h);	// ERROR "truncate|cannot convert"
    46  }
    47  

View as plain text