github.com/rsc/go@v0.0.0-20150416155037-e040fd465409/src/go/types/testdata/builtins.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  // builtin calls
     6  
     7  package builtins
     8  
     9  import "unsafe"
    10  
    11  func f0() {}
    12  
    13  func append1() {
    14  	var b byte
    15  	var x int
    16  	var s []byte
    17  	_ = append() // ERROR not enough arguments
    18  	_ = append("foo" /* ERROR not a slice */ )
    19  	_ = append(nil /* ERROR not a slice */ , s)
    20  	_ = append(x /* ERROR not a slice */ , s)
    21  	_ = append(s)
    22  	append /* ERROR not used */ (s)
    23  
    24  	_ = append(s, b)
    25  	_ = append(s, x /* ERROR cannot pass argument x */ )
    26  	_ = append(s, s /* ERROR cannot pass argument s */ )
    27  	_ = append(s... /* ERROR can only use ... with matching parameter */ )
    28  	_ = append(s, b, s... /* ERROR can only use ... with matching parameter */ )
    29  	_ = append(s, 1, 2, 3)
    30  	_ = append(s, 1, 2, 3, x /* ERROR cannot pass argument x */ , 5, 6, 6)
    31  	_ = append(s, 1, 2, s... /* ERROR can only use ... with matching parameter */ )
    32  	_ = append([]interface{}(nil), 1, 2, "foo", x, 3.1425, false)
    33  
    34  	type S []byte
    35  	type T string
    36  	var t T
    37  	_ = append(s, "foo" /* ERROR cannot convert */ )
    38  	_ = append(s, "foo"...)
    39  	_ = append(S(s), "foo" /* ERROR cannot convert */ )
    40  	_ = append(S(s), "foo"...)
    41  	_ = append(s, t /* ERROR cannot pass argument t */ )
    42  	_ = append(s, t...)
    43  	_ = append(s, T("foo")...)
    44  	_ = append(S(s), t /* ERROR cannot pass argument t */ )
    45  	_ = append(S(s), t...)
    46  	_ = append(S(s), T("foo")...)
    47  	_ = append([]string{}, t /* ERROR cannot pass argument t */ , "foo")
    48  	_ = append([]T{}, t, "foo")
    49  }
    50  
    51  // from the spec
    52  func append2() {
    53  	s0 := []int{0, 0}
    54  	s1 := append(s0, 2)                // append a single element     s1 == []int{0, 0, 2}
    55  	s2 := append(s1, 3, 5, 7)          // append multiple elements    s2 == []int{0, 0, 2, 3, 5, 7}
    56  	s3 := append(s2, s0...)            // append a slice              s3 == []int{0, 0, 2, 3, 5, 7, 0, 0}
    57  	s4 := append(s3[3:6], s3[2:]...)   // append overlapping slice    s4 == []int{3, 5, 7, 2, 3, 5, 7, 0, 0}
    58  
    59  	var t []interface{}
    60  	t = append(t, 42, 3.1415, "foo")   //                             t == []interface{}{42, 3.1415, "foo"}
    61  
    62  	var b []byte
    63  	b = append(b, "bar"...)            // append string contents      b == []byte{'b', 'a', 'r' }
    64  
    65  	_ = s4
    66  }
    67  
    68  func append3() {
    69  	f1 := func() (s []int) { return }
    70  	f2 := func() (s []int, x int) { return }
    71  	f3 := func() (s []int, x, y int) { return }
    72  	f5 := func() (s []interface{}, x int, y float32, z string, b bool) { return }
    73  	ff := func() (int, float32) { return 0, 0 }
    74  	_ = append(f0 /* ERROR used as value */ ())
    75  	_ = append(f1())
    76  	_ = append(f2())
    77  	_ = append(f3())
    78  	_ = append(f5())
    79  	_ = append(ff /* ERROR not a slice */ ()) // TODO(gri) better error message
    80  }
    81  
    82  func cap1() {
    83  	var a [10]bool
    84  	var p *[20]int
    85  	var c chan string
    86  	_ = cap() // ERROR not enough arguments
    87  	_ = cap(1, 2) // ERROR too many arguments
    88  	_ = cap(42 /* ERROR invalid */)
    89  	const _3 = cap(a)
    90  	assert(_3 == 10)
    91  	const _4 = cap(p)
    92  	assert(_4 == 20)
    93  	_ = cap(c)
    94  	cap /* ERROR not used */ (c)
    95  
    96  	// issue 4744
    97  	type T struct{ a [10]int }
    98  	const _ = cap(((*T)(nil)).a)
    99  
   100  	var s [][]byte
   101  	_ = cap(s)
   102  	_ = cap(s... /* ERROR invalid use of \.\.\. */ )
   103  }
   104  
   105  func cap2() {
   106  	f1a := func() (a [10]int) { return }
   107  	f1s := func() (s []int) { return }
   108  	f2 := func() (s []int, x int) { return }
   109  	_ = cap(f0 /* ERROR used as value */ ())
   110  	_ = cap(f1a())
   111  	_ = cap(f1s())
   112  	_ = cap(f2()) // ERROR too many arguments
   113  }
   114  
   115  // test cases for issue 7387
   116  func cap3() {
   117  	var f = func() int { return 0 }
   118  	var x = f()
   119  	const (
   120  		_ = cap([4]int{})
   121  		_ = cap([4]int{x})
   122  		_ = cap /* ERROR not constant */ ([4]int{f()})
   123  		_ = cap /* ERROR not constant */ ([4]int{cap([]int{})})
   124  		_ = cap([4]int{cap([4]int{})})
   125  	)
   126  	var y float64
   127  	var z complex128
   128  	const (
   129  		_ = cap([4]float64{})
   130  		_ = cap([4]float64{y})
   131  		_ = cap([4]float64{real(2i)})
   132  		_ = cap /* ERROR not constant */ ([4]float64{real(z)})
   133  	)
   134  	var ch chan [10]int
   135  	const (
   136  		_ = cap /* ERROR not constant */ (<-ch)
   137  		_ = cap /* ERROR not constant */ ([4]int{(<-ch)[0]})
   138  	)
   139  }
   140  
   141  func close1() {
   142  	var c chan int
   143  	var r <-chan int
   144  	close() // ERROR not enough arguments
   145  	close(1, 2) // ERROR too many arguments
   146  	close(42 /* ERROR not a channel */)
   147  	close(r /* ERROR receive-only channel */)
   148  	close(c)
   149  	_ = close /* ERROR used as value */ (c)
   150  
   151  	var s []chan int
   152  	close(s... /* ERROR invalid use of \.\.\. */ )
   153  }
   154  
   155  func close2() {
   156  	f1 := func() (ch chan int) { return }
   157  	f2 := func() (ch chan int, x int) { return }
   158  	close(f0 /* ERROR used as value */ ())
   159  	close(f1())
   160  	close(f2()) // ERROR too many arguments
   161  }
   162  
   163  func complex1() {
   164  	var i32 int32
   165  	var f32 float32
   166  	var f64 float64
   167  	var c64 complex64
   168  	var c128 complex128
   169  	_ = complex() // ERROR not enough arguments
   170  	_ = complex(1) // ERROR not enough arguments
   171  	_ = complex(true /* ERROR invalid argument */ , 0)
   172  	_ = complex(i32 /* ERROR invalid argument */ , 0)
   173  	_ = complex("foo" /* ERROR invalid argument */ , 0)
   174  	_ = complex(c64 /* ERROR invalid argument */ , 0)
   175  	_ = complex(0, true /* ERROR invalid argument */ )
   176  	_ = complex(0, i32 /* ERROR invalid argument */ )
   177  	_ = complex(0, "foo" /* ERROR invalid argument */ )
   178  	_ = complex(0, c64 /* ERROR invalid argument */ )
   179  	_ = complex(f32, f32)
   180  	_ = complex(f32, 1)
   181  	_ = complex(f32, 1.0)
   182  	_ = complex(f32, 'a')
   183  	_ = complex(f64, f64)
   184  	_ = complex(f64, 1)
   185  	_ = complex(f64, 1.0)
   186  	_ = complex(f64, 'a')
   187  	_ = complex(f32 /* ERROR mismatched types */ , f64)
   188  	_ = complex(f64 /* ERROR mismatched types */ , f32)
   189  	_ = complex(1, 1)
   190  	_ = complex(1, 1.1)
   191  	_ = complex(1, 'a')
   192  	complex /* ERROR not used */ (1, 2)
   193  
   194  	var _ complex64 = complex(f32, f32)
   195  	var _ complex64 = complex /* ERROR cannot initialize */ (f64, f64)
   196  
   197  	var _ complex128 = complex /* ERROR cannot initialize */ (f32, f32)
   198  	var _ complex128 = complex(f64, f64)
   199  
   200  	// untyped constants
   201  	const _ int = complex(1, 0)
   202  	const _ float32 = complex(1, 0)
   203  	const _ complex64 = complex(1, 0)
   204  	const _ complex128 = complex(1, 0)
   205  
   206  	const _ int = complex /* ERROR int */ (1.1, 0)
   207  	const _ float32 = complex /* ERROR float32 */ (1, 2)
   208  
   209  	// untyped values
   210  	var s uint
   211  	_ = complex(1 /* ERROR integer */ <<s, 0)
   212  	const _ = complex /* ERROR not constant */ (1 /* ERROR integer */ <<s, 0)
   213  	var _ int = complex /* ERROR cannot initialize */ (1 /* ERROR integer */ <<s, 0)
   214  
   215  	// floating-point argument types must be identical
   216  	type F32 float32
   217  	type F64 float64
   218  	var x32 F32
   219  	var x64 F64
   220  	c64 = complex(x32, x32)
   221  	_ = complex(x32 /* ERROR mismatched types */ , f32)
   222  	_ = complex(f32 /* ERROR mismatched types */ , x32)
   223  	c128 = complex(x64, x64)
   224  	_ = c128
   225  	_ = complex(x64 /* ERROR mismatched types */ , f64)
   226  	_ = complex(f64 /* ERROR mismatched types */ , x64)
   227  
   228  	var t []float32
   229  	_ = complex(t... /* ERROR invalid use of \.\.\. */ )
   230  }
   231  
   232  func complex2() {
   233  	f1 := func() (x float32) { return }
   234  	f2 := func() (x, y float32) { return }
   235  	f3 := func() (x, y, z float32) { return }
   236  	_ = complex(f0 /* ERROR used as value */ ())
   237  	_ = complex(f1()) // ERROR not enough arguments
   238  	_ = complex(f2())
   239  	_ = complex(f3()) // ERROR too many arguments
   240  }
   241  
   242  func copy1() {
   243  	copy() // ERROR not enough arguments
   244  	copy("foo") // ERROR not enough arguments
   245  	copy([ /* ERROR copy expects slice arguments */ ...]int{}, []int{})
   246  	copy([ /* ERROR copy expects slice arguments */ ]int{}, [...]int{})
   247  	copy([ /* ERROR different element types */ ]int8{}, "foo")
   248  
   249  	// spec examples
   250  	var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7}
   251  	var s = make([]int, 6)
   252  	var b = make([]byte, 5)
   253  	n1 := copy(s, a[0:])            // n1 == 6, s == []int{0, 1, 2, 3, 4, 5}
   254  	n2 := copy(s, s[2:])            // n2 == 4, s == []int{2, 3, 4, 5, 4, 5}
   255  	n3 := copy(b, "Hello, World!")  // n3 == 5, b == []byte("Hello")
   256  	_, _, _ = n1, n2, n3
   257  
   258  	var t [][]int
   259  	copy(t, t)
   260  	copy(t /* ERROR copy expects slice arguments */ , nil)
   261  	copy(nil /* ERROR copy expects slice arguments */ , t)
   262  	copy(nil /* ERROR copy expects slice arguments */ , nil)
   263  	copy(t... /* ERROR invalid use of \.\.\. */ )
   264  }
   265  
   266  func copy2() {
   267  	f1 := func() (a []int) { return }
   268  	f2 := func() (a, b []int) { return }
   269  	f3 := func() (a, b, c []int) { return }
   270  	copy(f0 /* ERROR used as value */ ())
   271  	copy(f1()) // ERROR not enough arguments
   272  	copy(f2())
   273  	copy(f3()) // ERROR too many arguments
   274  }
   275  
   276  func delete1() {
   277  	var m map[string]int
   278  	var s string
   279  	delete() // ERROR not enough arguments
   280  	delete(1) // ERROR not enough arguments
   281  	delete(1, 2, 3) // ERROR too many arguments
   282  	delete(m, 0 /* ERROR not assignable */)
   283  	delete(m, s)
   284  	_ = delete /* ERROR used as value */ (m, s)
   285  
   286  	var t []map[string]string
   287  	delete(t... /* ERROR invalid use of \.\.\. */ )
   288  }
   289  
   290  func delete2() {
   291  	f1 := func() (m map[string]int) { return }
   292  	f2 := func() (m map[string]int, k string) { return }
   293  	f3 := func() (m map[string]int, k string, x float32) { return }
   294  	delete(f0 /* ERROR used as value */ ())
   295  	delete(f1()) // ERROR not enough arguments
   296  	delete(f2())
   297  	delete(f3()) // ERROR too many arguments
   298  }
   299  
   300  func imag1() {
   301  	var f32 float32
   302  	var f64 float64
   303  	var c64 complex64
   304  	var c128 complex128
   305  	_ = imag() // ERROR not enough arguments
   306  	_ = imag(1, 2) // ERROR too many arguments
   307  	_ = imag(10 /* ERROR must be a complex number */)
   308  	_ = imag(2.7182818 /* ERROR must be a complex number */)
   309  	_ = imag("foo" /* ERROR must be a complex number */)
   310  	const _5 = imag(1 + 2i)
   311  	assert(_5 == 2)
   312  	f32 = _5
   313  	f64 = _5
   314  	const _6 = imag(0i)
   315  	assert(_6 == 0)
   316  	f32 = imag(c64)
   317  	f64 = imag(c128)
   318  	f32 = imag /* ERROR cannot assign */ (c128)
   319  	f64 = imag /* ERROR cannot assign */ (c64)
   320  	imag /* ERROR not used */ (c64)
   321  	_, _ = f32, f64
   322  
   323  	// complex type may not be predeclared
   324  	type C64 complex64
   325  	type C128 complex128
   326  	var x64 C64
   327  	var x128 C128
   328  	f32 = imag(x64)
   329  	f64 = imag(x128)
   330  
   331  	var s []complex64
   332  	_ = imag(s... /* ERROR invalid use of \.\.\. */ )
   333  }
   334  
   335  func imag2() {
   336  	f1 := func() (x complex128) { return }
   337  	f2 := func() (x, y complex128) { return }
   338  	_ = imag(f0 /* ERROR used as value */ ())
   339  	_ = imag(f1())
   340  	_ = imag(f2()) // ERROR too many arguments
   341  }
   342  
   343  func len1() {
   344  	const c = "foobar"
   345  	var a [10]bool
   346  	var p *[20]int
   347  	var m map[string]complex128
   348  	_ = len() // ERROR not enough arguments
   349  	_ = len(1, 2) // ERROR too many arguments
   350  	_ = len(42 /* ERROR invalid */)
   351  	const _3 = len(c)
   352  	assert(_3 == 6)
   353  	const _4 = len(a)
   354  	assert(_4 == 10)
   355  	const _5 = len(p)
   356  	assert(_5 == 20)
   357  	_ = len(m)
   358  	len /* ERROR not used */ (c)
   359  
   360  	// esoteric case
   361  	var t string
   362  	var hash map[interface{}][]*[10]int
   363  	const n = len /* ERROR not constant */ (hash[recover()][len(t)])
   364  	assert(n == 10) // ok because n has unknown value and no error is reported
   365  	var ch <-chan int
   366  	const nn = len /* ERROR not constant */ (hash[<-ch][len(t)])
   367  
   368  	// issue 4744
   369  	type T struct{ a [10]int }
   370  	const _ = len(((*T)(nil)).a)
   371  
   372  	var s [][]byte
   373  	_ = len(s)
   374  	_ = len(s... /* ERROR invalid use of \.\.\. */ )
   375  }
   376  
   377  func len2() {
   378  	f1 := func() (x []int) { return }
   379  	f2 := func() (x, y []int) { return }
   380  	_ = len(f0 /* ERROR used as value */ ())
   381  	_ = len(f1())
   382  	_ = len(f2()) // ERROR too many arguments
   383  }
   384  
   385  // test cases for issue 7387
   386  func len3() {
   387  	var f = func() int { return 0 }
   388  	var x = f()
   389  	const (
   390  		_ = len([4]int{})
   391  		_ = len([4]int{x})
   392  		_ = len /* ERROR not constant */ ([4]int{f()})
   393  		_ = len /* ERROR not constant */ ([4]int{len([]int{})})
   394  		_ = len([4]int{len([4]int{})})
   395  	)
   396  	var y float64
   397  	var z complex128
   398  	const (
   399  		_ = len([4]float64{})
   400  		_ = len([4]float64{y})
   401  		_ = len([4]float64{real(2i)})
   402  		_ = len /* ERROR not constant */ ([4]float64{real(z)})
   403  	)
   404  	var ch chan [10]int
   405  	const (
   406  		_ = len /* ERROR not constant */ (<-ch)
   407  		_ = len /* ERROR not constant */ ([4]int{(<-ch)[0]})
   408  	)
   409  }
   410  
   411  func make1() {
   412  	var n int
   413  	var m float32
   414  	var s uint
   415  
   416  	_ = make() // ERROR not enough arguments
   417  	_ = make(1 /* ERROR not a type */)
   418  	_ = make(int /* ERROR cannot make */)
   419  
   420  	// slices
   421  	_ = make/* ERROR arguments */ ([]int)
   422  	_ = make/* ERROR arguments */ ([]int, 2, 3, 4)
   423  	_ = make([]int, int /* ERROR not an expression */)
   424  	_ = make([]int, 10, float32 /* ERROR not an expression */)
   425  	_ = make([]int, "foo" /* ERROR cannot convert */)
   426  	_ = make([]int, 10, 2.3 /* ERROR truncated */)
   427  	_ = make([]int, 5, 10.0)
   428  	_ = make([]int, 0i)
   429  	_ = make([]int, 1.0)
   430  	_ = make([]int, 1.0<<s)
   431  	_ = make([]int, 1.1 /* ERROR int */ <<s)
   432  	_ = make([]int, - /* ERROR must not be negative */ 1, 10)
   433  	_ = make([]int, 0, - /* ERROR must not be negative */ 1)
   434  	_ = make([]int, - /* ERROR must not be negative */ 1, - /* ERROR must not be negative */ 1)
   435  	_ = make([]int, 1 /* ERROR overflows */ <<100, 1 /* ERROR overflows */ <<100)
   436  	_ = make([]int, 10 /* ERROR length and capacity swapped */ , 9)
   437  	_ = make([]int, 1 /* ERROR overflows */ <<100, 12345)
   438  	_ = make([]int, m /* ERROR must be integer */ )
   439          _ = &make /* ERROR cannot take address */ ([]int, 0)
   440  
   441  	// maps
   442  	_ = make /* ERROR arguments */ (map[int]string, 10, 20)
   443  	_ = make(map[int]float32, int /* ERROR not an expression */)
   444  	_ = make(map[int]float32, "foo" /* ERROR cannot convert */)
   445  	_ = make(map[int]float32, 10)
   446  	_ = make(map[int]float32, n)
   447  	_ = make(map[int]float32, int64(n))
   448  	_ = make(map[string]bool, 10.0)
   449  	_ = make(map[string]bool, 10.0<<s)
   450          _ = &make /* ERROR cannot take address */ (map[string]bool)
   451  
   452  	// channels
   453  	_ = make /* ERROR arguments */ (chan int, 10, 20)
   454  	_ = make(chan int, int /* ERROR not an expression */)
   455  	_ = make(chan<- int, "foo" /* ERROR cannot convert */)
   456  	_ = make(chan int, - /* ERROR must not be negative */ 10)
   457  	_ = make(<-chan float64, 10)
   458  	_ = make(chan chan int, n)
   459  	_ = make(chan string, int64(n))
   460  	_ = make(chan bool, 10.0)
   461  	_ = make(chan bool, 10.0<<s)
   462          _ = &make /* ERROR cannot take address */ (chan bool)
   463  
   464  	make /* ERROR not used */ ([]int, 10)
   465  
   466  	var t []int
   467  	_ = make([]int, t[0], t[1])
   468  	_ = make([]int, t... /* ERROR invalid use of \.\.\. */ )
   469  }
   470  
   471  func make2() {
   472  	f1 /* ERROR not used */ := func() (x []int) { return }
   473  	_ = make(f0 /* ERROR not a type */ ())
   474  	_ = make(f1 /* ERROR not a type */ ())
   475  }
   476  
   477  func new1() {
   478  	_ = new() // ERROR not enough arguments
   479  	_ = new(1, 2) // ERROR too many arguments
   480  	_ = new("foo" /* ERROR not a type */)
   481  	p := new(float64)
   482  	_ = new(struct{ x, y int })
   483  	q := new(*float64)
   484  	_ = *p == **q
   485  	new /* ERROR not used */ (int)
   486          _ = &new /* ERROR cannot take address */ (int)
   487  
   488  	_ = new(int... /* ERROR invalid use of \.\.\. */ )
   489  }
   490  
   491  func new2() {
   492  	f1 /* ERROR not used */ := func() (x []int) { return }
   493  	_ = new(f0 /* ERROR not a type */ ())
   494  	_ = new(f1 /* ERROR not a type */ ())
   495  }
   496  
   497  func panic1() {
   498  	panic() // ERROR not enough arguments
   499  	panic(1, 2) // ERROR too many arguments
   500  	panic(0)
   501  	panic("foo")
   502  	panic(false)
   503  	panic(1<<10)
   504  	panic(1 /* ERROR overflows */ <<1000)
   505  	_ = panic /* ERROR used as value */ (0)
   506  
   507  	var s []byte
   508  	panic(s)
   509  	panic(s... /* ERROR invalid use of \.\.\. */ )
   510  }
   511  
   512  func panic2() {
   513  	f1 := func() (x int) { return }
   514  	f2 := func() (x, y int) { return }
   515  	panic(f0 /* ERROR used as value */ ())
   516  	panic(f1())
   517  	panic(f2()) // ERROR too many arguments
   518  }
   519  
   520  func print1() {
   521  	print()
   522  	print(1)
   523  	print(1, 2)
   524  	print("foo")
   525  	print(2.718281828)
   526  	print(false)
   527  	print(1<<10)
   528  	print(1 /* ERROR overflows */ <<1000)
   529  	println(nil /* ERROR untyped nil */ )
   530  
   531  	var s []int
   532  	print(s... /* ERROR invalid use of \.\.\. */ )
   533  	_ = print /* ERROR used as value */ ()
   534  }
   535  
   536  func print2() {
   537  	f1 := func() (x int) { return }
   538  	f2 := func() (x, y int) { return }
   539  	f3 := func() (x int, y float32, z string) { return }
   540  	print(f0 /* ERROR used as value */ ())
   541  	print(f1())
   542  	print(f2())
   543  	print(f3())
   544  }
   545  
   546  func println1() {
   547  	println()
   548  	println(1)
   549  	println(1, 2)
   550  	println("foo")
   551  	println(2.718281828)
   552  	println(false)
   553  	println(1<<10)
   554  	println(1 /* ERROR overflows */ <<1000)
   555  	println(nil /* ERROR untyped nil */ )
   556  
   557  	var s []int
   558  	println(s... /* ERROR invalid use of \.\.\. */ )
   559  	_ = println /* ERROR used as value */ ()
   560  }
   561  
   562  func println2() {
   563  	f1 := func() (x int) { return }
   564  	f2 := func() (x, y int) { return }
   565  	f3 := func() (x int, y float32, z string) { return }
   566  	println(f0 /* ERROR used as value */ ())
   567  	println(f1())
   568  	println(f2())
   569  	println(f3())
   570  }
   571  
   572  func real1() {
   573  	var f32 float32
   574  	var f64 float64
   575  	var c64 complex64
   576  	var c128 complex128
   577  	_ = real() // ERROR not enough arguments
   578  	_ = real(1, 2) // ERROR too many arguments
   579  	_ = real(10 /* ERROR must be a complex number */)
   580  	_ = real(2.7182818 /* ERROR must be a complex number */)
   581  	_ = real("foo" /* ERROR must be a complex number */)
   582  	const _5 = real(1 + 2i)
   583  	assert(_5 == 1)
   584  	f32 = _5
   585  	f64 = _5
   586  	const _6 = real(0i)
   587  	assert(_6 == 0)
   588  	f32 = real(c64)
   589  	f64 = real(c128)
   590  	f32 = real /* ERROR cannot assign */ (c128)
   591  	f64 = real /* ERROR cannot assign */ (c64)
   592  	real /* ERROR not used */ (c64)
   593  
   594  	// complex type may not be predeclared
   595  	type C64 complex64
   596  	type C128 complex128
   597  	var x64 C64
   598  	var x128 C128
   599  	f32 = imag(x64)
   600  	f64 = imag(x128)
   601  
   602  	var s []complex64
   603  	_ = real(s... /* ERROR invalid use of \.\.\. */ )
   604  	_, _ = f32, f64
   605  }
   606  
   607  func real2() {
   608  	f1 := func() (x complex128) { return }
   609  	f2 := func() (x, y complex128) { return }
   610  	_ = real(f0 /* ERROR used as value */ ())
   611  	_ = real(f1())
   612  	_ = real(f2()) // ERROR too many arguments
   613  }
   614  
   615  func recover1() {
   616  	_ = recover()
   617  	_ = recover(10) // ERROR too many arguments
   618  	recover()
   619  
   620  	var s []int
   621  	recover(s... /* ERROR invalid use of \.\.\. */ )
   622  }
   623  
   624  func recover2() {
   625  	f1 := func() (x int) { return }
   626  	f2 := func() (x, y int) { return }
   627  	_ = recover(f0 /* ERROR used as value */ ())
   628  	_ = recover(f1()) // ERROR too many arguments
   629  	_ = recover(f2()) // ERROR too many arguments
   630  }
   631  
   632  // assuming types.DefaultPtrSize == 8
   633  type S0 struct{      // offset
   634  	a bool       //  0
   635  	b rune       //  4
   636  	c *int       //  8
   637  	d bool       // 16
   638  	e complex128 // 24
   639  }                    // 40
   640  
   641  type S1 struct{   // offset
   642  	x float32 //  0
   643  	y string  //  8
   644  	z *S1     // 24
   645  	S0        // 32
   646  }                 // 72
   647  
   648  type S2 struct{ // offset
   649  	*S1     //  0
   650  }               //  8
   651  
   652  type S3 struct { // offset
   653  	a int64  //  0
   654  	b int32  //  8
   655  }                // 12
   656  
   657  type S4 struct { // offset
   658  	S3       //  0
   659  	int32    // 12
   660  }                // 16
   661  
   662  type S5 struct {   // offset
   663  	a [3]int32 //  0
   664  	b int32    // 12
   665  }                  // 16
   666  
   667  func (S2) m() {}
   668  
   669  func Alignof1() {
   670  	var x int
   671  	_ = unsafe.Alignof() // ERROR not enough arguments
   672  	_ = unsafe.Alignof(1, 2) // ERROR too many arguments
   673  	_ = unsafe.Alignof(int /* ERROR not an expression */)
   674  	_ = unsafe.Alignof(42)
   675  	_ = unsafe.Alignof(new(struct{}))
   676  	_ = unsafe.Alignof(1<<10)
   677  	_ = unsafe.Alignof(1 /* ERROR overflows */ <<1000)
   678  	_ = unsafe.Alignof(nil /* ERROR "untyped nil */ )
   679  	unsafe /* ERROR not used */ .Alignof(x)
   680  
   681  	var y S0
   682  	assert(unsafe.Alignof(y.a) == 1)
   683  	assert(unsafe.Alignof(y.b) == 4)
   684  	assert(unsafe.Alignof(y.c) == 8)
   685  	assert(unsafe.Alignof(y.d) == 1)
   686  	assert(unsafe.Alignof(y.e) == 8)
   687  
   688  	var s []byte
   689  	_ = unsafe.Alignof(s)
   690  	_ = unsafe.Alignof(s... /* ERROR invalid use of \.\.\. */ )
   691  }
   692  
   693  func Alignof2() {
   694  	f1 := func() (x int32) { return }
   695  	f2 := func() (x, y int32) { return }
   696  	_ = unsafe.Alignof(f0 /* ERROR used as value */ ())
   697  	assert(unsafe.Alignof(f1()) == 4)
   698  	_ = unsafe.Alignof(f2()) // ERROR too many arguments
   699  }
   700  
   701  func Offsetof1() {
   702  	var x struct{ f int }
   703  	_ = unsafe.Offsetof() // ERROR not enough arguments
   704  	_ = unsafe.Offsetof(1, 2) // ERROR too many arguments
   705  	_ = unsafe.Offsetof(int /* ERROR not a selector expression */ )
   706  	_ = unsafe.Offsetof(x /* ERROR not a selector expression */ )
   707  	_ = unsafe.Offsetof(nil /* ERROR not a selector expression */ )
   708  	_ = unsafe.Offsetof(x.f)
   709  	_ = unsafe.Offsetof((x.f))
   710  	_ = unsafe.Offsetof((((((((x))).f)))))
   711  	unsafe /* ERROR not used */ .Offsetof(x.f)
   712  
   713  	var y0 S0
   714  	assert(unsafe.Offsetof(y0.a) == 0)
   715  	assert(unsafe.Offsetof(y0.b) == 4)
   716  	assert(unsafe.Offsetof(y0.c) == 8)
   717  	assert(unsafe.Offsetof(y0.d) == 16)
   718  	assert(unsafe.Offsetof(y0.e) == 24)
   719  
   720  	var y1 S1
   721  	assert(unsafe.Offsetof(y1.x) == 0)
   722  	assert(unsafe.Offsetof(y1.y) == 8)
   723  	assert(unsafe.Offsetof(y1.z) == 24)
   724  	assert(unsafe.Offsetof(y1.S0) == 32)
   725  
   726  	assert(unsafe.Offsetof(y1.S0.a) == 0) // relative to S0
   727  	assert(unsafe.Offsetof(y1.a) == 32)   // relative to S1
   728  	assert(unsafe.Offsetof(y1.b) == 36)   // relative to S1
   729  	assert(unsafe.Offsetof(y1.c) == 40)   // relative to S1
   730  	assert(unsafe.Offsetof(y1.d) == 48)   // relative to S1
   731  	assert(unsafe.Offsetof(y1.e) == 56)   // relative to S1
   732  
   733  	var y1p *S1
   734  	assert(unsafe.Offsetof(y1p.S0) == 32)
   735  
   736  	type P *S1
   737  	var p P = y1p
   738  	assert(unsafe.Offsetof(p.S0) == 32)
   739  
   740  	var y2 S2
   741  	assert(unsafe.Offsetof(y2.S1) == 0)
   742  	_ = unsafe.Offsetof(y2 /* ERROR embedded via a pointer */ .x)
   743  	_ = unsafe.Offsetof(y2 /* ERROR method value */ .m)
   744  
   745  	var s []byte
   746  	_ = unsafe.Offsetof(s... /* ERROR invalid use of \.\.\. */ )
   747  }
   748  
   749  func Offsetof2() {
   750  	f1 := func() (x int32) { return }
   751  	f2 := func() (x, y int32) { return }
   752  	_ = unsafe.Offsetof(f0 /* ERROR not a selector expression */ ())
   753  	_ = unsafe.Offsetof(f1 /* ERROR not a selector expression */ ())
   754  	_ = unsafe.Offsetof(f2 /* ERROR not a selector expression */ ())
   755  }
   756  
   757  func Sizeof1() {
   758  	var x int
   759  	_ = unsafe.Sizeof() // ERROR not enough arguments
   760  	_ = unsafe.Sizeof(1, 2) // ERROR too many arguments
   761  	_ = unsafe.Sizeof(int /* ERROR not an expression */)
   762  	_ = unsafe.Sizeof(42)
   763  	_ = unsafe.Sizeof(new(complex128))
   764  	_ = unsafe.Sizeof(1<<10)
   765  	_ = unsafe.Sizeof(1 /* ERROR overflows */ <<1000)
   766  	_ = unsafe.Sizeof(nil /* ERROR untyped nil */ )
   767  	unsafe /* ERROR not used */ .Sizeof(x)
   768  
   769  	// basic types have size guarantees
   770  	assert(unsafe.Sizeof(byte(0)) == 1)
   771  	assert(unsafe.Sizeof(uint8(0)) == 1)
   772  	assert(unsafe.Sizeof(int8(0)) == 1)
   773  	assert(unsafe.Sizeof(uint16(0)) == 2)
   774  	assert(unsafe.Sizeof(int16(0)) == 2)
   775  	assert(unsafe.Sizeof(uint32(0)) == 4)
   776  	assert(unsafe.Sizeof(int32(0)) == 4)
   777  	assert(unsafe.Sizeof(float32(0)) == 4)
   778  	assert(unsafe.Sizeof(uint64(0)) == 8)
   779  	assert(unsafe.Sizeof(int64(0)) == 8)
   780  	assert(unsafe.Sizeof(float64(0)) == 8)
   781  	assert(unsafe.Sizeof(complex64(0)) == 8)
   782  	assert(unsafe.Sizeof(complex128(0)) == 16)
   783  
   784  	var y0 S0
   785  	assert(unsafe.Sizeof(y0.a) == 1)
   786  	assert(unsafe.Sizeof(y0.b) == 4)
   787  	assert(unsafe.Sizeof(y0.c) == 8)
   788  	assert(unsafe.Sizeof(y0.d) == 1)
   789  	assert(unsafe.Sizeof(y0.e) == 16)
   790  	assert(unsafe.Sizeof(y0) == 40)
   791  
   792  	var y1 S1
   793  	assert(unsafe.Sizeof(y1) == 72)
   794  
   795  	var y2 S2
   796  	assert(unsafe.Sizeof(y2) == 8)
   797  
   798  	var y3 S3
   799  	assert(unsafe.Sizeof(y3) == 12)
   800  
   801  	var y4 S4
   802  	assert(unsafe.Sizeof(y4) == 16)
   803  
   804  	var y5 S5
   805  	assert(unsafe.Sizeof(y5) == 16)
   806  
   807  	var a3 [10]S3
   808  	assert(unsafe.Sizeof(a3) == 156)
   809  
   810  	// test case for issue 5670
   811  	type T struct {
   812  		a int32
   813  		_ int32
   814  		c int32
   815  	}
   816  	assert(unsafe.Sizeof(T{}) == 12)
   817  
   818  	var s []byte
   819  	_ = unsafe.Sizeof(s)
   820  	_ = unsafe.Sizeof(s... /* ERROR invalid use of \.\.\. */ )
   821  }
   822  
   823  func Sizeof2() {
   824  	f1 := func() (x int64) { return }
   825  	f2 := func() (x, y int64) { return }
   826  	_ = unsafe.Sizeof(f0 /* ERROR used as value */ ())
   827  	assert(unsafe.Sizeof(f1()) == 8)
   828  	_ = unsafe.Sizeof(f2()) // ERROR too many arguments
   829  }
   830  
   831  // self-testing only
   832  func assert1() {
   833  	var x int
   834  	assert() /* ERROR not enough arguments */
   835  	assert(1, 2) /* ERROR too many arguments */
   836  	assert("foo" /* ERROR boolean constant */ )
   837  	assert(x /* ERROR boolean constant */)
   838  	assert(true)
   839  	assert /* ERROR failed */ (false)
   840  	_ = assert(true)
   841  
   842  	var s []byte
   843  	assert(s... /* ERROR invalid use of \.\.\. */ )
   844  }
   845  
   846  func assert2() {
   847  	f1 := func() (x bool) { return }
   848  	f2 := func() (x bool) { return }
   849  	assert(f0 /* ERROR used as value */ ())
   850  	assert(f1 /* ERROR boolean constant */ ())
   851  	assert(f2 /* ERROR boolean constant */ ())
   852  }
   853  
   854  // self-testing only
   855  func trace1() {
   856  	// Uncomment the code below to test trace - will produce console output
   857  	// _ = trace /* ERROR no value */ ()
   858  	// _ = trace(1)
   859  	// _ = trace(true, 1.2, '\'', "foo", 42i, "foo" <= "bar")
   860  
   861  	var s []byte
   862  	trace(s... /* ERROR invalid use of \.\.\. */ )
   863  }
   864  
   865  func trace2() {
   866  	f1 := func() (x int) { return }
   867  	f2 := func() (x int, y string) { return }
   868  	f3 := func() (x int, y string, z []int) { return }
   869  	_ = f1
   870  	_ = f2
   871  	_ = f3
   872  	// Uncomment the code below to test trace - will produce console output
   873  	// trace(f0())
   874  	// trace(f1())
   875  	// trace(f2())
   876  	// trace(f3())
   877  	// trace(f0(), 1)
   878  	// trace(f1(), 1, 2)
   879  	// trace(f2(), 1, 2, 3)
   880  	// trace(f3(), 1, 2, 3, 4)
   881  }