modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue20530.go (about)

     1  // run
     2  
     3  // Copyright 2017 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  var a uint8
    10  
    11  //go:noinline
    12  func f() {
    13  	b := int8(func() int32 { return -1 }())
    14  	a = uint8(b)
    15  	if int32(a) != 255 {
    16  		// Failing case prints 'got 255 expected 255'
    17  		println("got", a, "expected 255")
    18  	}
    19  }
    20  
    21  //go:noinline
    22  func g() {
    23  	b := int8(func() uint32 { return 0xffffffff }())
    24  	a = uint8(b)
    25  	if int32(a) != 255 {
    26  		// Failing case prints 'got 255 expected 255'
    27  		println("got", a, "expected 255")
    28  	}
    29  }
    30  
    31  func main() {
    32  	f()
    33  	g()
    34  }