github.com/zebozhuang/go@v0.0.0-20200207033046-f8a98f6f5c5d/src/go/types/testdata/expr1.src (about) 1 // Copyright 2012 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 // binary expressions 6 7 package expr1 8 9 type mybool bool 10 11 func _(x, y bool, z mybool) { 12 x = x || y 13 x = x || true 14 x = x || false 15 x = x && y 16 x = x && true 17 x = x && false 18 19 z = z /* ERROR mismatched types */ || y 20 z = z || true 21 z = z || false 22 z = z /* ERROR mismatched types */ && y 23 z = z && true 24 z = z && false 25 } 26 27 type myint int 28 29 func _(x, y int, z myint) { 30 x = x + 1 31 x = x + 1.0 32 x = x + 1.1 // ERROR truncated to int 33 x = x + y 34 x = x - y 35 x = x * y 36 x = x / y 37 x = x % y 38 x = x << y // ERROR must be unsigned integer 39 x = x >> y // ERROR must be unsigned integer 40 41 z = z + 1 42 z = z + 1.0 43 z = z + 1.1 // ERROR truncated to int 44 z = z /* ERROR mismatched types */ + y 45 z = z /* ERROR mismatched types */ - y 46 z = z /* ERROR mismatched types */ * y 47 z = z /* ERROR mismatched types */ / y 48 z = z /* ERROR mismatched types */ % y 49 z = z << y // ERROR must be unsigned integer 50 z = z >> y // ERROR must be unsigned integer 51 } 52 53 type myuint uint 54 55 func _(x, y uint, z myuint) { 56 x = x + 1 57 x = x + - /* ERROR overflows uint */ 1 58 x = x + 1.0 59 x = x + 1.1 // ERROR truncated to uint 60 x = x + y 61 x = x - y 62 x = x * y 63 x = x / y 64 x = x % y 65 x = x << y 66 x = x >> y 67 68 z = z + 1 69 z = x + - /* ERROR overflows uint */ 1 70 z = z + 1.0 71 z = z + 1.1 // ERROR truncated to uint 72 z = z /* ERROR mismatched types */ + y 73 z = z /* ERROR mismatched types */ - y 74 z = z /* ERROR mismatched types */ * y 75 z = z /* ERROR mismatched types */ / y 76 z = z /* ERROR mismatched types */ % y 77 z = z << y 78 z = z >> y 79 } 80 81 type myfloat64 float64 82 83 func _(x, y float64, z myfloat64) { 84 x = x + 1 85 x = x + -1 86 x = x + 1.0 87 x = x + 1.1 88 x = x + y 89 x = x - y 90 x = x * y 91 x = x / y 92 x = x /* ERROR not defined */ % y 93 x = x /* ERROR operand x .* must be integer */ << y 94 x = x /* ERROR operand x .* must be integer */ >> y 95 96 z = z + 1 97 z = z + -1 98 z = z + 1.0 99 z = z + 1.1 100 z = z /* ERROR mismatched types */ + y 101 z = z /* ERROR mismatched types */ - y 102 z = z /* ERROR mismatched types */ * y 103 z = z /* ERROR mismatched types */ / y 104 z = z /* ERROR mismatched types */ % y 105 z = z /* ERROR operand z .* must be integer */ << y 106 z = z /* ERROR operand z .* must be integer */ >> y 107 } 108 109 type mystring string 110 111 func _(x, y string, z mystring) { 112 x = x + "foo" 113 x = x /* ERROR not defined */ - "foo" 114 x = x + 1 // ERROR cannot convert 115 x = x + y 116 x = x /* ERROR not defined */ - y 117 x = x * 10 // ERROR cannot convert 118 } 119 120 func f() (a, b int) { return } 121 122 func _(x int) { 123 _ = f /* ERROR 2-valued f */ () + 1 124 _ = x + f /* ERROR 2-valued f */ () 125 _ = f /* ERROR 2-valued f */ () + f 126 _ = f /* ERROR 2-valued f */ () + f /* ERROR 2-valued f */ () 127 }