// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // builtin calls package builtins import "unsafe" func f0() {} func append1() { var b byte var x int var s []byte _ = append() // ERROR not enough arguments _ = append("foo" /* ERROR not a slice */ ) _ = append(nil /* ERROR not a slice */ , s) _ = append(x /* ERROR not a slice */ , s) _ = append(s) _ = append(s, nil...) append /* ERROR not used */ (s) _ = append(s, b) _ = append(s, x /* ERROR cannot use x */ ) _ = append(s, s /* ERROR cannot use s */ ) _ = append(s... /* ERROR can only use ... with matching parameter */ ) _ = append(s, b, s... /* ERROR can only use ... with matching parameter */ ) _ = append(s, 1, 2, 3) _ = append(s, 1, 2, 3, x /* ERROR cannot use x */ , 5, 6, 6) _ = append(s, 1, 2, s... /* ERROR can only use ... with matching parameter */ ) _ = append([]interface{}(nil), 1, 2, "foo", x, 3.1425, false) type S []byte type T string var t T _ = append(s, "foo" /* ERROR cannot convert */ ) _ = append(s, "foo"...) _ = append(S(s), "foo" /* ERROR cannot convert */ ) _ = append(S(s), "foo"...) _ = append(s, t /* ERROR cannot use t */ ) _ = append(s, t...) _ = append(s, T("foo")...) _ = append(S(s), t /* ERROR cannot use t */ ) _ = append(S(s), t...) _ = append(S(s), T("foo")...) _ = append([]string{}, t /* ERROR cannot use t */ , "foo") _ = append([]T{}, t, "foo") } // from the spec func append2() { s0 := []int{0, 0} s1 := append(s0, 2) // append a single element s1 == []int{0, 0, 2} s2 := append(s1, 3, 5, 7) // append multiple elements s2 == []int{0, 0, 2, 3, 5, 7} s3 := append(s2, s0...) // append a slice s3 == []int{0, 0, 2, 3, 5, 7, 0, 0} s4 := append(s3[3:6], s3[2:]...) // append overlapping slice s4 == []int{3, 5, 7, 2, 3, 5, 7, 0, 0} var t []interface{} t = append(t, 42, 3.1415, "foo") // t == []interface{}{42, 3.1415, "foo"} var b []byte b = append(b, "bar"...) // append string contents b == []byte{'b', 'a', 'r' } _ = s4 } func append3() { f1 := func() (s []int) { return } f2 := func() (s []int, x int) { return } f3 := func() (s []int, x, y int) { return } f5 := func() (s []interface{}, x int, y float32, z string, b bool) { return } ff := func() (int, float32) { return 0, 0 } _ = append(f0 /* ERROR used as value */ ()) _ = append(f1()) _ = append(f2()) _ = append(f3()) _ = append(f5()) _ = append(ff /* ERROR not a slice */ ()) // TODO(gri) better error message } func cap1() { var a [10]bool var p *[20]int var c chan string _ = cap() // ERROR not enough arguments _ = cap(1, 2) // ERROR too many arguments _ = cap(42 /* ERROR invalid */) const _3 = cap(a) assert(_3 == 10) const _4 = cap(p) assert(_4 == 20) _ = cap(c) cap /* ERROR not used */ (c) // issue 4744 type T struct{ a [10]int } const _ = cap(((*T)(nil)).a) var s [][]byte _ = cap(s) _ = cap(s... /* ERROR invalid use of \.\.\. */ ) } func cap2() { f1a := func() (a [10]int) { return } f1s := func() (s []int) { return } f2 := func() (s []int, x int) { return } _ = cap(f0 /* ERROR used as value */ ()) _ = cap(f1a()) _ = cap(f1s()) _ = cap(f2()) // ERROR too many arguments } // test cases for issue 7387 func cap3() { var f = func() int { return 0 } var x = f() const ( _ = cap([4]int{}) _ = cap([4]int{x}) _ = cap /* ERROR not constant */ ([4]int{f()}) _ = cap /* ERROR not constant */ ([4]int{cap([]int{})}) _ = cap([4]int{cap([4]int{})}) ) var y float64 var z complex128 const ( _ = cap([4]float64{}) _ = cap([4]float64{y}) _ = cap([4]float64{real(2i)}) _ = cap /* ERROR not constant */ ([4]float64{real(z)}) ) var ch chan [10]int const ( _ = cap /* ERROR not constant */ (<-ch) _ = cap /* ERROR not constant */ ([4]int{(<-ch)[0]}) ) } func close1() { var c chan int var r <-chan int close() // ERROR not enough arguments close(1, 2) // ERROR too many arguments close(42 /* ERROR not a channel */) close(r /* ERROR receive-only channel */) close(c) _ = close /* ERROR used as value */ (c) var s []chan int close(s... /* ERROR invalid use of \.\.\. */ ) } func close2() { f1 := func() (ch chan int) { return } f2 := func() (ch chan int, x int) { return } close(f0 /* ERROR used as value */ ()) close(f1()) close(f2()) // ERROR too many arguments } func complex1() { var i32 int32 var f32 float32 var f64 float64 var c64 complex64 var c128 complex128 _ = complex() // ERROR not enough arguments _ = complex(1) // ERROR not enough arguments _ = complex(true /* ERROR mismatched types */ , 0) _ = complex(i32 /* ERROR expected floating-point */ , 0) _ = complex("foo" /* ERROR mismatched types */ , 0) _ = complex(c64 /* ERROR expected floating-point */ , 0) _ = complex(0 /* ERROR mismatched types */ , true) _ = complex(0 /* ERROR expected floating-point */ , i32) _ = complex(0 /* ERROR mismatched types */ , "foo") _ = complex(0 /* ERROR expected floating-point */ , c64) _ = complex(f32, f32) _ = complex(f32, 1) _ = complex(f32, 1.0) _ = complex(f32, 'a') _ = complex(f64, f64) _ = complex(f64, 1) _ = complex(f64, 1.0) _ = complex(f64, 'a') _ = complex(f32 /* ERROR mismatched types */ , f64) _ = complex(f64 /* ERROR mismatched types */ , f32) _ = complex(1, 1) _ = complex(1, 1.1) _ = complex(1, 'a') complex /* ERROR not used */ (1, 2) var _ complex64 = complex(f32, f32) var _ complex64 = complex /* ERROR cannot use .* in variable declaration */ (f64, f64) var _ complex128 = complex /* ERROR cannot use .* in variable declaration */ (f32, f32) var _ complex128 = complex(f64, f64) // untyped constants const _ int = complex(1, 0) const _ float32 = complex(1, 0) const _ complex64 = complex(1, 0) const _ complex128 = complex(1, 0) const _ = complex(0i, 0i) const _ = complex(0i, 0) const _ int = 1.0 + complex(1, 0i) const _ int = complex /* ERROR int */ (1.1, 0) const _ float32 = complex /* ERROR float32 */ (1, 2) // untyped values var s uint _ = complex(1 /* ERROR integer */ <