github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/tests/files/type37.gno (about)

     1  package main
     2  
     3  import "fmt"
     4  
     5  type IntArray []int
     6  type Arr *IntArray
     7  
     8  func (a Arr) Add(x int) { // receiver is val, not ptr
     9  	*a = append(*a, x)
    10  }
    11  
    12  func main() {
    13  	a := new(IntArray)
    14  	Arr(a).Add(4)
    15  
    16  	fmt.Println(*a)
    17  }
    18  
    19  // Error:
    20  // main/files/type37.gno:8: invalid receiver type main.Arr (base type is pointer type)