...
Run Format

Text file src/go/types/testdata/expr0.src

Documentation: go/types/testdata

     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		// byte
    29		_ = byte(0)
    30		_ = byte(- /* ERROR "cannot convert" */ 1)
    31		_ = - /* ERROR "-byte\(1\) \(constant -1 of type byte\) overflows byte" */ byte(1) // test for issue 11367
    32		_ = byte /* ERROR "overflows byte" */ (0) - byte(1)
    33	
    34		// int
    35		i0 = 1
    36		i1 int = i0
    37		i2 = +1
    38		i3 = +i0
    39		i4 int = +1
    40		i5 int = +i4
    41		i6 = -1
    42		i7 = -i0
    43		i8 int = -1
    44		i9 int = -i4
    45		i10 = !i0 /* ERROR "not defined" */
    46		i11 = ^1
    47		i12 = ^i0
    48		i13 int = ^1
    49		i14 int = ^i4
    50		i15 = *i0 /* ERROR "cannot indirect" */
    51		i16 = &i0
    52		i17 = *i16
    53		i18 = <-i16 /* ERROR "cannot receive" */
    54	
    55		// uint
    56		u0 = uint(1)
    57		u1 uint = u0
    58		u2 = +1
    59		u3 = +u0
    60		u4 uint = +1
    61		u5 uint = +u4
    62		u6 = -1
    63		u7 = -u0
    64		u8 uint = - /* ERROR "overflows" */ 1
    65		u9 uint = -u4
    66		u10 = !u0 /* ERROR "not defined" */
    67		u11 = ^1
    68		u12 = ^i0
    69		u13 uint = ^ /* ERROR "overflows" */ 1
    70		u14 uint = ^u4
    71		u15 = *u0 /* ERROR "cannot indirect" */
    72		u16 = &u0
    73		u17 = *u16
    74		u18 = <-u16 /* ERROR "cannot receive" */
    75		u19 = ^uint(0)
    76	
    77		// float64
    78		f0 = float64(1)
    79		f1 float64 = f0
    80		f2 = +1
    81		f3 = +f0
    82		f4 float64 = +1
    83		f5 float64 = +f4
    84		f6 = -1
    85		f7 = -f0
    86		f8 float64 = -1
    87		f9 float64 = -f4
    88		f10 = !f0 /* ERROR "not defined" */
    89		f11 = ^1
    90		f12 = ^i0
    91		f13 float64 = ^1
    92		f14 float64 = ^f4 /* ERROR "not defined" */
    93		f15 = *f0 /* ERROR "cannot indirect" */
    94		f16 = &f0
    95		f17 = *u16
    96		f18 = <-u16 /* ERROR "cannot receive" */
    97	
    98		// complex128
    99		c0 = complex128(1)
   100		c1 complex128 = c0
   101		c2 = +1
   102		c3 = +c0
   103		c4 complex128 = +1
   104		c5 complex128 = +c4
   105		c6 = -1
   106		c7 = -c0
   107		c8 complex128 = -1
   108		c9 complex128 = -c4
   109		c10 = !c0 /* ERROR "not defined" */
   110		c11 = ^1
   111		c12 = ^i0
   112		c13 complex128 = ^1
   113		c14 complex128 = ^c4 /* ERROR "not defined" */
   114		c15 = *c0 /* ERROR "cannot indirect" */
   115		c16 = &c0
   116		c17 = *u16
   117		c18 = <-u16 /* ERROR "cannot receive" */
   118	
   119		// string
   120		s0 = "foo"
   121		s1 = +"foo" /* ERROR "not defined" */
   122		s2 = -s0 /* ERROR "not defined" */
   123		s3 = !s0 /* ERROR "not defined" */
   124		s4 = ^s0 /* ERROR "not defined" */
   125		s5 = *s4
   126		s6 = &s4
   127		s7 = *s6
   128		s8 = <-s7
   129	
   130		// channel
   131		ch chan int
   132		rc <-chan float64
   133		sc chan <- string
   134		ch0 = +ch /* ERROR "not defined" */
   135		ch1 = -ch /* ERROR "not defined" */
   136		ch2 = !ch /* ERROR "not defined" */
   137		ch3 = ^ch /* ERROR "not defined" */
   138		ch4 = *ch /* ERROR "cannot indirect" */
   139		ch5 = &ch
   140		ch6 = *ch5
   141		ch7 = <-ch
   142		ch8 = <-rc
   143		ch9 = <-sc /* ERROR "cannot receive" */
   144		ch10, ok = <-ch
   145		// ok is of type bool
   146		ch11, myok = <-ch
   147		_ mybool = myok /* ERROR "cannot use .* in variable declaration" */
   148	)
   149	
   150	// address of composite literals
   151	type T struct{x, y int}
   152	
   153	func f() T { return T{} }
   154	
   155	var (
   156		_ = &T{1, 2}
   157		_ = &[...]int{}
   158		_ = &[]int{}
   159		_ = &[]int{}
   160		_ = &map[string]T{}
   161		_ = &(T{1, 2})
   162		_ = &((((T{1, 2}))))
   163		_ = &f /* ERROR "cannot take address" */ ()
   164	)
   165	
   166	// recursive pointer types
   167	type P *P
   168	
   169	var (
   170		p1 P = new(P)
   171		p2 P = *p1
   172		p3 P = &p2
   173	)
   174	
   175	func g() (a, b int) { return }
   176	
   177	func _() {
   178		_ = -g /* ERROR 2-valued g */ ()
   179		_ = <-g /* ERROR 2-valued g */ ()
   180	}

View as plain text