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

     1  package main
     2  
     3  import "fmt"
     4  
     5  type Integer int
     6  
     7  func (i **Integer) Add(x int) {
     8  	**i += Integer(x) // Dereference twice to get to the actual Integer value and modify it
     9  }
    10  
    11  func main() {
    12  	a := new(Integer) // a is a pointer to Integer
    13  	b := &a           // b is a pointer to a pointer to Integer
    14  
    15  	// Since Add is defined on **Integer, you need to pass b
    16  	b.Add(4) // Adds 4 to the value **b points to
    17  
    18  	fmt.Println(**b) // Should print 4, as **b is the same as *a
    19  }
    20  
    21  // Error:
    22  // main/files/type37b.gno:7: invalid receiver type **main.Integer (base type is pointer type)