Source file test/fixedbugs/bug517.go

     1  // run
     2  
     3  // Copyright 2023 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  // The gofrontend used to mishandle this code due to a pass ordering issue.
     8  // It was inconsistent as to whether unsafe.Sizeof(byte(0)) was a constant,
     9  // and therefore as to whether it was a direct-iface type.
    10  
    11  package main
    12  
    13  import "unsafe"
    14  
    15  type A [unsafe.Sizeof(byte(0))]*byte
    16  
    17  func (r A) V() byte {
    18  	return *r[0]
    19  }
    20  
    21  func F() byte {
    22  	panic("F") // should never be called
    23  }
    24  
    25  type B [unsafe.Sizeof(F())]*byte
    26  
    27  func (r B) V() byte {
    28  	return *r[0]
    29  }
    30  
    31  func main() {
    32  	b := byte(1)
    33  	v := A{&b}.V() + B{&b}.V()
    34  	if v != 2 {
    35  		panic(v)
    36  	}
    37  }
    38  

View as plain text