Source file test/varinit.go

     1  // run
     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  // Test var x = x + 1 works.
     8  
     9  package main
    10  
    11  func main() {
    12  	var x int = 1
    13  	if x != 1 {
    14  		print("found ", x, ", expected 1\n")
    15  		panic("fail")
    16  	}
    17  	{
    18  		var x int = x + 1
    19  		if x != 2 {
    20  			print("found ", x, ", expected 2\n")
    21  			panic("fail")
    22  		}
    23  	}
    24  	{
    25  		x := x + 1
    26  		if x != 2 {
    27  			print("found ", x, ", expected 2\n")
    28  			panic("fail")
    29  		}
    30  	}
    31  }
    32  

View as plain text