Source file test/fixedbugs/bug491.go

     1  // run
     2  
     3  // Copyright 2014 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  // Test order of calls to builtin functions.
     8  // Discovered during CL 144530045 review.
     9  
    10  package main
    11  
    12  func main() {
    13  	// append
    14  	{
    15  		x := make([]int, 0)
    16  		f := func() int { x = make([]int, 2); return 2 }
    17  		a, b, c := append(x, 1), f(), append(x, 1)
    18  		if len(a) != 1 || len(c) != 3 {
    19  			bug()
    20  			println("append call not ordered:", len(a), b, len(c))
    21  		}
    22  	}
    23  
    24  	// cap
    25  	{
    26  		x := make([]int, 1)
    27  		f := func() int { x = make([]int, 3); return 2 }
    28  		a, b, c := cap(x), f(), cap(x)
    29  		if a != 1 || c != 3 {
    30  			bug()
    31  			println("cap call not ordered:", a, b, c)
    32  		}
    33  	}
    34  
    35  	// complex
    36  	{
    37  		x := 1.0
    38  		f := func() int { x = 3; return 2 }
    39  		a, b, c := complex(x, 0), f(), complex(x, 0)
    40  		if real(a) != 1 || real(c) != 3 {
    41  			bug()
    42  			println("complex call not ordered:", a, b, c)
    43  		}
    44  	}
    45  
    46  	// copy
    47  	{
    48  		tmp := make([]int, 100)
    49  		x := make([]int, 1)
    50  		f := func() int { x = make([]int, 3); return 2 }
    51  		a, b, c := copy(tmp, x), f(), copy(tmp, x)
    52  		if a != 1 || c != 3 {
    53  			bug()
    54  			println("copy call not ordered:", a, b, c)
    55  		}
    56  	}
    57  
    58  	// imag
    59  	{
    60  		x := 1i
    61  		f := func() int { x = 3i; return 2 }
    62  		a, b, c := imag(x), f(), imag(x)
    63  		if a != 1 || c != 3 {
    64  			bug()
    65  			println("imag call not ordered:", a, b, c)
    66  		}
    67  	}
    68  
    69  	// len
    70  	{
    71  		x := make([]int, 1)
    72  		f := func() int { x = make([]int, 3); return 2 }
    73  		a, b, c := len(x), f(), len(x)
    74  		if a != 1 || c != 3 {
    75  			bug()
    76  			println("len call not ordered:", a, b, c)
    77  		}
    78  	}
    79  
    80  	// make
    81  	{
    82  		x := 1
    83  		f := func() int { x = 3; return 2 }
    84  		a, b, c := make([]int, x), f(), make([]int, x)
    85  		if len(a) != 1 || len(c) != 3 {
    86  			bug()
    87  			println("make call not ordered:", len(a), b, len(c))
    88  		}
    89  	}
    90  
    91  	// real
    92  	{
    93  		x := 1 + 0i
    94  		f := func() int { x = 3; return 2 }
    95  		a, b, c := real(x), f(), real(x)
    96  		if a != 1 || c != 3 {
    97  			bug()
    98  			println("real call not ordered:", a, b, c)
    99  		}
   100  	}
   101  }
   102  
   103  var bugged = false
   104  
   105  func bug() {
   106  	if !bugged {
   107  		println("BUG")
   108  		bugged = true
   109  	}
   110  }

View as plain text