...
Run Format

Text file src/go/types/testdata/decls1.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	// variable declarations
     6	
     7	package decls1
     8	
     9	import (
    10		"math"
    11	)
    12	
    13	// Global variables without initialization
    14	var (
    15		a, b bool
    16		c byte
    17		d uint8
    18		r rune
    19		i int
    20		j, k, l int
    21		x, y float32
    22		xx, yy float64
    23		u, v complex64
    24		uu, vv complex128
    25		s, t string
    26		array []byte
    27		iface interface{}
    28	
    29		blank _ /* ERROR "cannot use _" */
    30	)
    31	
    32	// Global variables with initialization
    33	var (
    34		s1 = i + j
    35		s2 = i /* ERROR "mismatched types" */ + x
    36		s3 = c + d
    37		s4 = s + t
    38		s5 = s /* ERROR "invalid operation" */ / t
    39		s6 = array[t1]
    40		s7 = array[x /* ERROR "integer" */]
    41		s8 = &a
    42		s10 = &42 /* ERROR "cannot take address" */
    43		s11 = &v
    44		s12 = -(u + *t11) / *&v
    45		s13 = a /* ERROR "shifted operand" */ << d
    46		s14 = i << j /* ERROR "must be unsigned" */
    47		s18 = math.Pi * 10.0
    48		s19 = s1 /* ERROR "cannot call" */ ()
    49	 	s20 = f0 /* ERROR "no value" */ ()
    50		s21 = f6(1, s1, i)
    51		s22 = f6(1, s1, uu /* ERROR "cannot use .* in argument" */ )
    52	
    53		t1 int = i + j
    54		t2 int = i /* ERROR "mismatched types" */ + x
    55		t3 int = c /* ERROR "cannot use .* variable declaration" */ + d
    56		t4 string = s + t
    57		t5 string = s /* ERROR "invalid operation" */ / t
    58		t6 byte = array[t1]
    59		t7 byte = array[x /* ERROR "must be integer" */]
    60		t8 *int = & /* ERROR "cannot use .* variable declaration" */ a
    61		t10 *int = &42 /* ERROR "cannot take address" */
    62		t11 *complex64 = &v
    63		t12 complex64 = -(u + *t11) / *&v
    64		t13 int = a /* ERROR "shifted operand" */ << d
    65		t14 int = i << j /* ERROR "must be unsigned" */
    66		t15 math /* ERROR "not in selector" */
    67		t16 math /* ERROR "not declared" */ .xxx
    68		t17 math /* ERROR "not a type" */ .Pi
    69		t18 float64 = math.Pi * 10.0
    70		t19 int = t1 /* ERROR "cannot call" */ ()
    71		t20 int = f0 /* ERROR "no value" */ ()
    72		t21 int = a /* ERROR "cannot use .* variable declaration" */
    73	)
    74	
    75	// Various more complex expressions
    76	var (
    77		u1 = x /* ERROR "not an interface" */ .(int)
    78		u2 = iface.([]int)
    79		u3 = iface.(a /* ERROR "not a type" */ )
    80		u4, ok = iface.(int)
    81		u5, ok2, ok3 = iface /* ERROR "cannot initialize" */ .(int)
    82	)
    83	
    84	// Constant expression initializations
    85	var (
    86		v1 = 1 /* ERROR "cannot convert" */ + "foo"
    87		v2 = c + 255
    88		v3 = c + 256 /* ERROR "overflows" */
    89		v4 = r + 2147483647
    90		v5 = r + 2147483648 /* ERROR "overflows" */
    91		v6 = 42
    92		v7 = v6 + 9223372036854775807
    93		v8 = v6 + 9223372036854775808 /* ERROR "overflows" */
    94		v9 = i + 1 << 10
    95		v10 byte = 1024 /* ERROR "overflows" */
    96		v11 = xx/yy*yy - xx
    97		v12 = true && false
    98		v13 = nil /* ERROR "use of untyped nil" */
    99	)
   100	
   101	// Multiple assignment expressions
   102	var (
   103		m1a, m1b = 1, 2
   104		m2a, m2b, m2c /* ERROR "missing init expr for m2c" */ = 1, 2
   105		m3a, m3b = 1, 2, 3 /* ERROR "extra init expr 3" */
   106	)
   107	
   108	func _() {
   109		var (
   110			m1a, m1b = 1, 2
   111			m2a, m2b, m2c /* ERROR "missing init expr for m2c" */ = 1, 2
   112			m3a, m3b = 1, 2, 3 /* ERROR "extra init expr 3" */
   113		)
   114	
   115		_, _ = m1a, m1b
   116		_, _, _ = m2a, m2b, m2c
   117		_, _ = m3a, m3b
   118	}
   119	
   120	// Declaration of parameters and results
   121	func f0() {}
   122	func f1(a /* ERROR "not a type" */) {}
   123	func f2(a, b, c d /* ERROR "not a type" */) {}
   124	
   125	func f3() int { return 0 }
   126	func f4() a /* ERROR "not a type" */ { return 0 }
   127	func f5() (a, b, c d /* ERROR "not a type" */) { return }
   128	
   129	func f6(a, b, c int) complex128 { return 0 }
   130	
   131	// Declaration of receivers
   132	type T struct{}
   133	
   134	func (T) m0() {}
   135	func (*T) m1() {}
   136	func (x T) m2() {}
   137	func (x *T) m3() {}
   138	
   139	// Initialization functions
   140	func init() {}
   141	func /* ERROR "no arguments and no return values" */ init(int) {}
   142	func /* ERROR "no arguments and no return values" */ init() int { return 0 }
   143	func /* ERROR "no arguments and no return values" */ init(int) int { return 0 }
   144	func (T) init(int) int { return 0 }

View as plain text