github.com/rsc/go@v0.0.0-20150416155037-e040fd465409/src/go/types/testdata/expr0.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 // unary expressions 6 7 package expr0 8 9 type mybool bool 10 11 var ( 12 // bool 13 b0 = true 14 b1 bool = b0 15 b2 = !true 16 b3 = !b1 17 b4 bool = !true 18 b5 bool = !b4 19 b6 = +b0 /* ERROR "not defined" */ 20 b7 = -b0 /* ERROR "not defined" */ 21 b8 = ^b0 /* ERROR "not defined" */ 22 b9 = *b0 /* ERROR "cannot indirect" */ 23 b10 = &true /* ERROR "cannot take address" */ 24 b11 = &b0 25 b12 = <-b0 /* ERROR "cannot receive" */ 26 b13 = & & /* ERROR "cannot take address" */ b0 27 28 // int 29 i0 = 1 30 i1 int = i0 31 i2 = +1 32 i3 = +i0 33 i4 int = +1 34 i5 int = +i4 35 i6 = -1 36 i7 = -i0 37 i8 int = -1 38 i9 int = -i4 39 i10 = !i0 /* ERROR "not defined" */ 40 i11 = ^1 41 i12 = ^i0 42 i13 int = ^1 43 i14 int = ^i4 44 i15 = *i0 /* ERROR "cannot indirect" */ 45 i16 = &i0 46 i17 = *i16 47 i18 = <-i16 /* ERROR "cannot receive" */ 48 49 // uint 50 u0 = uint(1) 51 u1 uint = u0 52 u2 = +1 53 u3 = +u0 54 u4 uint = +1 55 u5 uint = +u4 56 u6 = -1 57 u7 = -u0 58 u8 uint = - /* ERROR "overflows" */ 1 59 u9 uint = -u4 60 u10 = !u0 /* ERROR "not defined" */ 61 u11 = ^1 62 u12 = ^i0 63 u13 uint = ^ /* ERROR "overflows" */ 1 64 u14 uint = ^u4 65 u15 = *u0 /* ERROR "cannot indirect" */ 66 u16 = &u0 67 u17 = *u16 68 u18 = <-u16 /* ERROR "cannot receive" */ 69 u19 = ^uint(0) 70 71 // float64 72 f0 = float64(1) 73 f1 float64 = f0 74 f2 = +1 75 f3 = +f0 76 f4 float64 = +1 77 f5 float64 = +f4 78 f6 = -1 79 f7 = -f0 80 f8 float64 = -1 81 f9 float64 = -f4 82 f10 = !f0 /* ERROR "not defined" */ 83 f11 = ^1 84 f12 = ^i0 85 f13 float64 = ^1 86 f14 float64 = ^f4 /* ERROR "not defined" */ 87 f15 = *f0 /* ERROR "cannot indirect" */ 88 f16 = &f0 89 f17 = *u16 90 f18 = <-u16 /* ERROR "cannot receive" */ 91 92 // complex128 93 c0 = complex128(1) 94 c1 complex128 = c0 95 c2 = +1 96 c3 = +c0 97 c4 complex128 = +1 98 c5 complex128 = +c4 99 c6 = -1 100 c7 = -c0 101 c8 complex128 = -1 102 c9 complex128 = -c4 103 c10 = !c0 /* ERROR "not defined" */ 104 c11 = ^1 105 c12 = ^i0 106 c13 complex128 = ^1 107 c14 complex128 = ^c4 /* ERROR "not defined" */ 108 c15 = *c0 /* ERROR "cannot indirect" */ 109 c16 = &c0 110 c17 = *u16 111 c18 = <-u16 /* ERROR "cannot receive" */ 112 113 // string 114 s0 = "foo" 115 s1 = +"foo" /* ERROR "not defined" */ 116 s2 = -s0 /* ERROR "not defined" */ 117 s3 = !s0 /* ERROR "not defined" */ 118 s4 = ^s0 /* ERROR "not defined" */ 119 s5 = *s4 120 s6 = &s4 121 s7 = *s6 122 s8 = <-s7 123 124 // channel 125 ch chan int 126 rc <-chan float64 127 sc chan <- string 128 ch0 = +ch /* ERROR "not defined" */ 129 ch1 = -ch /* ERROR "not defined" */ 130 ch2 = !ch /* ERROR "not defined" */ 131 ch3 = ^ch /* ERROR "not defined" */ 132 ch4 = *ch /* ERROR "cannot indirect" */ 133 ch5 = &ch 134 ch6 = *ch5 135 ch7 = <-ch 136 ch8 = <-rc 137 ch9 = <-sc /* ERROR "cannot receive" */ 138 ch10, ok = <-ch 139 // ok is of type bool 140 ch11, myok = <-ch 141 _ mybool = myok /* ERROR "cannot initialize" */ 142 ) 143 144 // address of composite literals 145 type T struct{x, y int} 146 147 func f() T { return T{} } 148 149 var ( 150 _ = &T{1, 2} 151 _ = &[...]int{} 152 _ = &[]int{} 153 _ = &[]int{} 154 _ = &map[string]T{} 155 _ = &(T{1, 2}) 156 _ = &((((T{1, 2})))) 157 _ = &f /* ERROR "cannot take address" */ () 158 ) 159 160 // recursive pointer types 161 type P *P 162 163 var ( 164 p1 P = new(P) 165 p2 P = *p1 166 p3 P = &p2 167 ) 168