github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/internal/types/testdata/check/init2.go (about)

     1  // Copyright 2014 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  // initialization cycles
     6  
     7  package init2
     8  
     9  // cycles through functions
    10  
    11  func f1() int { _ = x1; return 0 }
    12  var x1 /* ERROR initialization cycle */ = f1
    13  
    14  func f2() int { _ = x2; return 0 }
    15  var x2 /* ERROR initialization cycle */ = f2()
    16  
    17  // cycles through method expressions
    18  
    19  type T3 int
    20  func (T3) m() int { _ = x3; return 0 }
    21  var x3 /* ERROR initialization cycle */ = T3.m
    22  
    23  type T4 int
    24  func (T4) m() int { _ = x4; return 0 }
    25  var x4 /* ERROR initialization cycle */ = T4.m(0)
    26  
    27  type T3p int
    28  func (*T3p) m() int { _ = x3p; return 0 }
    29  var x3p /* ERROR initialization cycle */ = (*T3p).m
    30  
    31  type T4p int
    32  func (*T4p) m() int { _ = x4p; return 0 }
    33  var x4p /* ERROR initialization cycle */ = (*T4p).m(nil)
    34  
    35  // cycles through method expressions of embedded methods
    36  
    37  type T5 struct { E5 }
    38  type E5 int
    39  func (E5) m() int { _ = x5; return 0 }
    40  var x5 /* ERROR initialization cycle */ = T5.m
    41  
    42  type T6 struct { E6 }
    43  type E6 int
    44  func (E6) m() int { _ = x6; return 0 }
    45  var x6 /* ERROR initialization cycle */ = T6.m(T6{0})
    46  
    47  type T5p struct { E5p }
    48  type E5p int
    49  func (*E5p) m() int { _ = x5p; return 0 }
    50  var x5p /* ERROR initialization cycle */ = (*T5p).m
    51  
    52  type T6p struct { E6p }
    53  type E6p int
    54  func (*E6p) m() int { _ = x6p; return 0 }
    55  var x6p /* ERROR initialization cycle */ = (*T6p).m(nil)
    56  
    57  // cycles through method values
    58  
    59  type T7 int
    60  func (T7) m() int { _ = x7; return 0 }
    61  var x7 /* ERROR initialization cycle */ = T7(0).m
    62  
    63  type T8 int
    64  func (T8) m() int { _ = x8; return 0 }
    65  var x8 /* ERROR initialization cycle */ = T8(0).m()
    66  
    67  type T7p int
    68  func (*T7p) m() int { _ = x7p; return 0 }
    69  var x7p /* ERROR initialization cycle */ = new(T7p).m
    70  
    71  type T8p int
    72  func (*T8p) m() int { _ = x8p; return 0 }
    73  var x8p /* ERROR initialization cycle */ = new(T8p).m()
    74  
    75  type T7v int
    76  func (T7v) m() int { _ = x7v; return 0 }
    77  var x7var T7v
    78  var x7v /* ERROR initialization cycle */ = x7var.m
    79  
    80  type T8v int
    81  func (T8v) m() int { _ = x8v; return 0 }
    82  var x8var T8v
    83  var x8v /* ERROR initialization cycle */ = x8var.m()
    84  
    85  type T7pv int
    86  func (*T7pv) m() int { _ = x7pv; return 0 }
    87  var x7pvar *T7pv
    88  var x7pv /* ERROR initialization cycle */ = x7pvar.m
    89  
    90  type T8pv int
    91  func (*T8pv) m() int { _ = x8pv; return 0 }
    92  var x8pvar *T8pv
    93  var x8pv /* ERROR initialization cycle */ = x8pvar.m()
    94  
    95  // cycles through method values of embedded methods
    96  
    97  type T9 struct { E9 }
    98  type E9 int
    99  func (E9) m() int { _ = x9; return 0 }
   100  var x9 /* ERROR initialization cycle */ = T9{0}.m
   101  
   102  type T10 struct { E10 }
   103  type E10 int
   104  func (E10) m() int { _ = x10; return 0 }
   105  var x10 /* ERROR initialization cycle */ = T10{0}.m()
   106  
   107  type T9p struct { E9p }
   108  type E9p int
   109  func (*E9p) m() int { _ = x9p; return 0 }
   110  var x9p /* ERROR initialization cycle */ = new(T9p).m
   111  
   112  type T10p struct { E10p }
   113  type E10p int
   114  func (*E10p) m() int { _ = x10p; return 0 }
   115  var x10p /* ERROR initialization cycle */ = new(T10p).m()
   116  
   117  type T9v struct { E9v }
   118  type E9v int
   119  func (E9v) m() int { _ = x9v; return 0 }
   120  var x9var T9v
   121  var x9v /* ERROR initialization cycle */ = x9var.m
   122  
   123  type T10v struct { E10v }
   124  type E10v int
   125  func (E10v) m() int { _ = x10v; return 0 }
   126  var x10var T10v
   127  var x10v /* ERROR initialization cycle */ = x10var.m()
   128  
   129  type T9pv struct { E9pv }
   130  type E9pv int
   131  func (*E9pv) m() int { _ = x9pv; return 0 }
   132  var x9pvar *T9pv
   133  var x9pv /* ERROR initialization cycle */ = x9pvar.m
   134  
   135  type T10pv struct { E10pv }
   136  type E10pv int
   137  func (*E10pv) m() int { _ = x10pv; return 0 }
   138  var x10pvar *T10pv
   139  var x10pv /* ERROR initialization cycle */ = x10pvar.m()