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

     1  // Copyright 2022 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  // Field accesses through type parameters are disabled
     6  // until we have a more thorough understanding of the
     7  // implications on the spec. See issue #51576.
     8  
     9  package p
    10  
    11  type Sf struct {
    12          f int
    13  }
    14  
    15  func f0[P Sf](p P) {
    16          _ = p.f // ERROR p\.f undefined
    17          p.f /* ERROR p\.f undefined */ = 0
    18  }
    19  
    20  func f0t[P ~struct{f int}](p P) {
    21          _ = p.f // ERROR p\.f undefined
    22          p.f /* ERROR p\.f undefined */ = 0
    23  }
    24  
    25  var _ = f0[Sf]
    26  var _ = f0t[Sf]
    27  
    28  var _ = f0[Sm /* ERROR does not satisfy */ ]
    29  var _ = f0t[Sm /* ERROR does not satisfy */ ]
    30  
    31  func f1[P interface{ Sf; m() }](p P) {
    32          _ = p.f // ERROR p\.f undefined
    33          p.f /* ERROR p\.f undefined */ = 0
    34          p.m()
    35  }
    36  
    37  var _ = f1[Sf /* ERROR missing method m */ ]
    38  var _ = f1[Sm /* ERROR does not satisfy */ ]
    39  
    40  type Sm struct {}
    41  
    42  func (Sm) m() {}
    43  
    44  type Sfm struct {
    45          f int
    46  }
    47  
    48  func (Sfm) m() {}
    49  
    50  func f2[P interface{ Sfm; m() }](p P) {
    51          _ = p.f // ERROR p\.f undefined
    52          p.f /* ERROR p\.f undefined */ = 0
    53          p.m()
    54  }
    55  
    56  var _ = f2[Sfm]
    57  
    58  // special case: core type is a named pointer type
    59  
    60  type PSfm *Sfm
    61  
    62  func f3[P interface{ PSfm }](p P) {
    63          _ = p.f // ERROR p\.f undefined
    64          p.f /* ERROR p\.f undefined */ = 0
    65          p.m /* ERROR type P has no field or method m */ ()
    66  }
    67  
    68  var _ = f3[PSfm]