"Fossies" - the Fresh Open Source Software Archive

Member "go/test/typeparam/mdempsky/14.go" (26 Apr 2023, 568 Bytes) of package /linux/misc/go1.20.4.src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // run
    2 
    3 // Copyright 2021 The Go Authors. All rights reserved.
    4 // Use of this source code is governed by a BSD-style
    5 // license that can be found in the LICENSE file.
    6 
    7 package main
    8 
    9 // Zero returns the zero value of T
   10 func Zero[T any]() (_ T) {
   11     return
   12 }
   13 
   14 type AnyInt[X any] int
   15 
   16 func (AnyInt[X]) M() {
   17     var have interface{} = Zero[X]()
   18     var want interface{} = Zero[MyInt]()
   19 
   20     if have != want {
   21         println("FAIL")
   22     }
   23 }
   24 
   25 type I interface{ M() }
   26 
   27 type MyInt int
   28 type U = AnyInt[MyInt]
   29 
   30 var x = U(0)
   31 var i I = x
   32 
   33 func main() {
   34     x.M()
   35     U.M(x)
   36     (*U).M(&x)
   37 
   38     i.M()
   39     I.M(x)
   40 }