Text file src/go/types/testdata/fixedbugs/issue49276.go2

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package p
     6  
     7  import "unsafe"
     8  
     9  type S /* ERROR illegal cycle in declaration of S */ struct {
    10  	_ [unsafe.Sizeof(s)]byte
    11  }
    12  
    13  var s S
    14  
    15  // Since f is a pointer, this case could be valid.
    16  // But it's pathological and not worth the expense.
    17  type T struct {
    18  	f *[unsafe.Sizeof(T /* ERROR illegal cycle in type declaration */ {})]int
    19  }
    20  
    21  // a mutually recursive case using unsafe.Sizeof
    22  type (
    23  	A1 struct {
    24  		_ [unsafe.Sizeof(B1{})]int
    25  	}
    26  
    27  	B1 struct {
    28  		_ [unsafe.Sizeof(A1 /* ERROR illegal cycle in type declaration */ {})]int
    29  	}
    30  )
    31  
    32  // a mutually recursive case using len
    33  type (
    34  	A2 struct {
    35  		f [len(B2{}.f)]int
    36  	}
    37  
    38  	B2 struct {
    39  		f [len(A2 /* ERROR illegal cycle in type declaration */ {}.f)]int
    40  	}
    41  )
    42  
    43  // test case from issue
    44  type a struct {
    45  	_ [42 - unsafe.Sizeof(a /* ERROR illegal cycle in type declaration */ {})]byte
    46  }
    47  

View as plain text