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

     1  // Copyright 2026 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  type M[T any] interface {
     8  	m() T
     9  }
    10  
    11  func f[T any](x interface{ m() T }) T { return x.m() }
    12  func g[T any](x M[T]) T               { return x.m() }
    13  
    14  type S struct{}
    15  
    16  // inference must work here even though m is declared only afterwards
    17  // (inference must type-check m as needed)
    18  var _ = f(S{})
    19  var _ = g(S{})
    20  
    21  func _() {
    22  	var s S
    23  	var _ = f(s)
    24  	var _ = g(s)
    25  }
    26  
    27  func (S) m() int { return 0 }
    28  
    29  var _ = f(S{})
    30  var _ = g(S{})
    31  

View as plain text