Source file test/const8.go

     1  // run
     2  
     3  // Copyright 2022 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 that identifiers in implicit (omitted) RHS
     8  // expressions of constant declarations are resolved
     9  // in the correct context; see issues #49157, #53585.
    10  
    11  package main
    12  
    13  const X = 2
    14  
    15  func main() {
    16  	const (
    17  		A    = iota // 0
    18  		iota = iota // 1
    19  		B           // 1 (iota is declared locally on prev. line)
    20  		C           // 1
    21  	)
    22  	if A != 0 || B != 1 || C != 1 {
    23  		println("got", A, B, C, "want 0 1 1")
    24  		panic("FAILED")
    25  	}
    26  
    27  	const (
    28  		X = X + X
    29  		Y
    30  		Z = iota
    31  	)
    32  	if X != 4 || Y != 8 || Z != 1 {
    33  		println("got", X, Y, Z, "want 4 8 1")
    34  		panic("FAILED")
    35  	}
    36  }
    37  

View as plain text