modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/ken/robfunc.go (about)

     1  // run
     2  
     3  // Copyright 2009 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  // Test functions of many signatures.
     8  
     9  package main
    10  
    11  func assertequal(is, shouldbe int, msg string) {
    12  	if is != shouldbe {
    13  		print("assertion fail" + msg + "\n")
    14  		panic(1)
    15  	}
    16  }
    17  
    18  func f1() {
    19  }
    20  
    21  func f2(a int) {
    22  }
    23  
    24  func f3(a, b int) int {
    25  	return a + b
    26  }
    27  
    28  func f4(a, b int, c float64) int {
    29  	return (a+b)/2 + int(c)
    30  }
    31  
    32  func f5(a int) int {
    33  	return 5
    34  }
    35  
    36  func f6(a int) (r int) {
    37  	return 6
    38  }
    39  
    40  func f7(a int) (x int, y float64) {
    41  	return 7, 7.0
    42  }
    43  
    44  
    45  func f8(a int) (x int, y float64) {
    46  	return 8, 8.0
    47  }
    48  
    49  type T struct {
    50  	x, y int
    51  }
    52  
    53  func (t *T) m10(a int, b float64) int {
    54  	return (t.x + a) * (t.y + int(b))
    55  }
    56  
    57  
    58  func f9(a int) (in int, fl float64) {
    59  	i := 9
    60  	f := float64(9)
    61  	return i, f
    62  }
    63  
    64  
    65  func main() {
    66  	f1()
    67  	f2(1)
    68  	r3 := f3(1, 2)
    69  	assertequal(r3, 3, "3")
    70  	r4 := f4(0, 2, 3.0)
    71  	assertequal(r4, 4, "4")
    72  	r5 := f5(1)
    73  	assertequal(r5, 5, "5")
    74  	r6 := f6(1)
    75  	assertequal(r6, 6, "6")
    76  	var r7 int
    77  	var s7 float64
    78  	r7, s7 = f7(1)
    79  	assertequal(r7, 7, "r7")
    80  	assertequal(int(s7), 7, "s7")
    81  	var r8 int
    82  	var s8 float64
    83  	r8, s8 = f8(1)
    84  	assertequal(r8, 8, "r8")
    85  	assertequal(int(s8), 8, "s8")
    86  	var r9 int
    87  	var s9 float64
    88  	r9, s9 = f9(1)
    89  	assertequal(r9, 9, "r9")
    90  	assertequal(int(s9), 9, "s9")
    91  	var t *T = new(T)
    92  	t.x = 1
    93  	t.y = 2
    94  	r10 := t.m10(1, 3.0)
    95  	assertequal(r10, 10, "10")
    96  }