Source file src/internal/types/testdata/check/conversions1.27.go

     1  // -lang=go1.27
     2  
     3  // Copyright 2026 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  // This is a replica of the string conversions in conversions0.go at Go 1.27
     8  // to ensure that integer-to-string conversions are accepted without error in Go 1.27.
     9  
    10  package conversions
    11  
    12  func string_conversions() {
    13  	const A = string(65)
    14  	assert(A == "A")
    15  	const E = string(-1)
    16  	assert(E == "\uFFFD")
    17  	assert(E == string(1234567890))
    18  
    19  	type myint int
    20  	assert(A == string(myint(65)))
    21  
    22  	var i int
    23  	_ = string(i)
    24  
    25  	var b byte
    26  	_ = string(b)
    27  
    28  	var r rune
    29  	_ = string(r)
    30  
    31  	const _ = string('a')
    32  	const _ = string('\xf8')
    33  	const _ = string(byte(65))
    34  	const _ = string(rune(65))
    35  
    36  	type mystring string
    37  	const _ mystring = mystring("foo")
    38  
    39  	const _ = string(true /* ERROR "cannot convert" */ )
    40  	const _ = string(1.2 /* ERROR "cannot convert" */ )
    41  	const _ = string(nil /* ERROR "cannot convert" */ )
    42  
    43  	// issues 11357, 11353: argument must be of integer type
    44  	_ = string(0.0 /* ERROR "cannot convert" */ )
    45  	_ = string(0i /* ERROR "cannot convert" */ )
    46  	_ = string(1 /* ERROR "cannot convert" */ + 2i)
    47  }
    48  

View as plain text