Source file src/internal/types/testdata/fixedbugs/issue49276.go

     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 "invalid recursive type 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 "invalid recursive type" */ {})]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 "invalid recursive type" */ {})]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 "invalid recursive type" */ {}.f)]int
    40  	}
    41  )
    42  
    43  // test case from issue
    44  type a struct {
    45  	_ [42 - unsafe.Sizeof(a /* ERROR "invalid recursive type" */ {})]byte
    46  }
    47  

View as plain text