github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/src/go/types/testdata/stmt0.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  // statements
     6  
     7  package stmt0
     8  
     9  func assignments0() (int, int) {
    10  	var a, b, c int
    11  	var ch chan int
    12  	f0 := func() {}
    13  	f1 := func() int { return 1 }
    14  	f2 := func() (int, int) { return 1, 2 }
    15  	f3 := func() (int, int, int) { return 1, 2, 3 }
    16  
    17  	a, b, c = 1, 2, 3
    18  	a, b, c = 1 /* ERROR "assignment count mismatch" */ , 2
    19  	a, b, c = 1 /* ERROR "assignment count mismatch" */ , 2, 3, 4
    20  	_, _, _ = a, b, c
    21  
    22  	a = f0 /* ERROR "used as value" */ ()
    23  	a = f1()
    24  	a = f2 /* ERROR "assignment count mismatch" */ ()
    25  	a, b = f2()
    26  	a, b, c = f2 /* ERROR "assignment count mismatch" */ ()
    27  	a, b, c = f3()
    28  	a, b = f3 /* ERROR "assignment count mismatch" */ ()
    29  
    30  	a, b, c = <- /* ERROR "assignment count mismatch" */ ch
    31  
    32  	return /* ERROR "wrong number of return values" */
    33  	return /* ERROR "wrong number of return values" */ 1
    34  	return 1, 2
    35  	return /* ERROR "wrong number of return values" */ 1, 2, 3
    36  }
    37  
    38  func assignments1() {
    39  	b, i, f, c, s := false, 1, 1.0, 1i, "foo"
    40  	b = i /* ERROR "cannot use .* in assignment" */
    41  	i = f /* ERROR "cannot use .* in assignment" */
    42  	f = c /* ERROR "cannot use .* in assignment" */
    43  	c = s /* ERROR "cannot use .* in assignment" */
    44  	s = b /* ERROR "cannot use .* in assignment" */
    45  
    46  	v0, v1, v2 := 1 /* ERROR "mismatch" */ , 2, 3, 4
    47  	_, _, _ = v0, v1, v2
    48  
    49  	b = true
    50  
    51  	i += 1
    52  	i += "foo" /* ERROR "cannot convert.*int" */
    53  
    54  	f -= 1
    55  	f /= 0
    56  	f = float32(0)/0 /* ERROR "division by zero" */
    57  	f -= "foo" /* ERROR "cannot convert.*float64" */
    58  
    59  	c *= 1
    60  	c /= 0
    61  
    62  	s += "bar"
    63  	s += 1 /* ERROR "cannot convert.*string" */
    64  
    65  	var u64 uint64
    66  	u64 += 1<<u64
    67  
    68  	undeclared /* ERROR "undeclared" */ = 991
    69  
    70  	// test cases for issue 5800
    71  	var (
    72  		_ int = nil /* ERROR "untyped nil value" */
    73  		_ [10]int = nil /* ERROR "untyped nil value" */
    74  		_ []byte = nil
    75  		_ struct{} = nil /* ERROR "untyped nil value" */
    76  		_ func() = nil
    77  		_ map[int]string = nil
    78  		_ chan int = nil
    79  	)
    80  
    81  	// test cases for issue 5500
    82  	_ = func() (int, bool) {
    83  		var m map[int]int
    84  		return /* ERROR "wrong number of return values" */ m[0]
    85  	}
    86  
    87  	g := func(int, bool){}
    88  	var m map[int]int
    89  	g(m[0]) /* ERROR "too few arguments" */
    90  
    91  	// assignments to _
    92  	_ = nil /* ERROR "use of untyped nil" */
    93  	_ = 1 /* ERROR overflow */ <<1000
    94  	(_) = 0
    95  }
    96  
    97  func assignments2() {
    98  	type mybool bool
    99  	var m map[string][]bool
   100  	var s []bool
   101  	var b bool
   102  	var d mybool
   103  	_ = s
   104  	_ = b
   105  	_ = d
   106  
   107  	// assignments to map index expressions are ok
   108  	s, b = m["foo"]
   109  	_, d = m["bar"]
   110  	m["foo"] = nil
   111  	m["foo"] = nil /* ERROR assignment count mismatch */ , false
   112  	_ = append(m["foo"])
   113  	_ = append(m["foo"], true)
   114  
   115  	var c chan int
   116  	_, b = <-c
   117  	_, d = <-c
   118  	<- /* ERROR cannot assign */ c = 0
   119  	<-c = 0 /* ERROR assignment count mismatch */ , false
   120  
   121  	var x interface{}
   122  	_, b = x.(int)
   123  	x /* ERROR cannot assign */ .(int) = 0
   124  	x.(int) = 0 /* ERROR assignment count mismatch */ , false
   125  
   126  	assignments2 /* ERROR used as value */ () = nil
   127  	int /* ERROR not an expression */ = 0
   128  }
   129  
   130  func issue6487() {
   131  	type S struct{x int}
   132  	_ = &S /* ERROR "cannot take address" */ {}.x
   133  	_ = &( /* ERROR "cannot take address" */ S{}.x)
   134  	_ = (&S{}).x
   135  	S /* ERROR "cannot assign" */ {}.x = 0
   136  	(&S{}).x = 0
   137  
   138  	type M map[string]S
   139  	var m M
   140  	m /* ERROR "cannot assign to struct field" */ ["foo"].x = 0
   141  	_ = &( /* ERROR "cannot take address" */ m["foo"].x)
   142  	_ = &m /* ERROR "cannot take address" */ ["foo"].x
   143  }
   144  
   145  func issue6766a() {
   146  	a, a /* ERROR redeclared */ := 1, 2
   147  	_ = a
   148  	a, b, b /* ERROR redeclared */ := 1, 2, 3
   149  	_ = b
   150  	c, c /* ERROR redeclared */, b := 1, 2, 3
   151  	_ = c
   152  	a, b := /* ERROR no new variables */ 1, 2
   153  }
   154  
   155  func shortVarDecls1() {
   156  	const c = 0
   157  	type d int
   158  	a, b, c /* ERROR "cannot assign" */ , d /* ERROR "cannot assign" */  := 1, "zwei", 3.0, 4
   159  	var _ int = a // a is of type int
   160  	var _ string = b // b is of type string
   161  }
   162  
   163  func incdecs() {
   164  	const c = 3.14
   165  	c /* ERROR "cannot assign" */ ++
   166  	s := "foo"
   167  	s /* ERROR "invalid operation" */ --
   168  	3.14 /* ERROR "cannot assign" */ ++
   169  	var (
   170  		x int
   171  		y float32
   172  		z complex128
   173  	)
   174  	x++
   175  	y--
   176  	z++
   177  }
   178  
   179  func sends() {
   180  	var ch chan int
   181  	var rch <-chan int
   182  	var x int
   183  	x <- /* ERROR "cannot send" */ x
   184  	rch <- /* ERROR "cannot send" */ x
   185  	ch <- "foo" /* ERROR "cannot convert" */
   186  	ch <- x
   187  }
   188  
   189  func selects() {
   190  	select {}
   191  	var (
   192  		ch chan int
   193  		sc chan <- bool
   194  	)
   195  	select {
   196  	case <-ch:
   197  	case (<-ch):
   198  	case t := <-ch:
   199  		_ = t
   200  	case t := (<-ch):
   201  		_ = t
   202  	case t, ok := <-ch:
   203  		_, _ = t, ok
   204  	case t, ok := (<-ch):
   205  		_, _ = t, ok
   206  	case <-sc /* ERROR "cannot receive from send-only channel" */ :
   207  	}
   208  	select {
   209  	default:
   210  	default /* ERROR "multiple defaults" */ :
   211  	}
   212  	select {
   213  	case a, b := <-ch:
   214  		_, b = a, b
   215  	case x /* ERROR send or receive */ :
   216  	case a /* ERROR send or receive */ := ch:
   217  	}
   218  
   219  	// test for issue 9570: ch2 in second case falsely resolved to
   220  	// ch2 declared in body of first case
   221  	ch1 := make(chan int)
   222  	ch2 := make(chan int)
   223  	select {
   224  	case <-ch1:
   225  		var ch2 /* ERROR ch2 declared but not used */ chan bool
   226  	case i := <-ch2:
   227  		print(i + 1)
   228  	}
   229  }
   230  
   231  func gos() {
   232  	go 1 /* ERROR HERE "function must be invoked" */
   233  	go int /* ERROR "go requires function call, not conversion" */ (0)
   234  	go gos()
   235  	var c chan int
   236  	go close(c)
   237  	go len /* ERROR "go discards result" */ (c)
   238  }
   239  
   240  func defers() {
   241  	defer 1 /* ERROR HERE "function must be invoked" */
   242  	defer int /* ERROR "defer requires function call, not conversion" */ (0)
   243  	defer defers()
   244  	var c chan int
   245  	defer close(c)
   246  	defer len /* ERROR "defer discards result" */ (c)
   247  }
   248  
   249  func breaks() {
   250  	var x, y int
   251  
   252  	break /* ERROR "break" */
   253  	{
   254  		break /* ERROR "break" */
   255  	}
   256  	if x < y {
   257  		break /* ERROR "break" */
   258  	}
   259  
   260  	switch x {
   261  	case 0:
   262  		break
   263  	case 1:
   264  		if x == y {
   265  			break
   266  		}
   267  	default:
   268  		break
   269  		break
   270  	}
   271  
   272  	var z interface{}
   273  	switch z.(type) {
   274  	case int:
   275  		break
   276  	}
   277  
   278  	for {
   279  		break
   280  	}
   281  
   282  	var a []int
   283  	for _ = range a {
   284  		break
   285  	}
   286  
   287  	for {
   288  		if x == y {
   289  			break
   290  		}
   291  	}
   292  
   293  	var ch chan int
   294  	select {
   295  	case <-ch:
   296  		break
   297  	}
   298  
   299  	select {
   300  	case <-ch:
   301  		if x == y {
   302  			break
   303  		}
   304  	default:
   305  		break
   306  	}
   307  }
   308  
   309  func continues() {
   310  	var x, y int
   311  
   312  	continue /* ERROR "continue" */
   313  	{
   314  		continue /* ERROR "continue" */
   315  	}
   316  
   317  	if x < y {
   318  		continue /* ERROR "continue" */
   319  	}
   320  
   321  	switch x {
   322  	case 0:
   323  		continue /* ERROR "continue" */
   324  	}
   325  
   326  	var z interface{}
   327  	switch z.(type) {
   328  	case int:
   329  		continue /* ERROR "continue" */
   330  	}
   331  
   332  	var ch chan int
   333  	select {
   334  	case <-ch:
   335  		continue /* ERROR "continue" */
   336  	}
   337  
   338  	for i := 0; i < 10; i++ {
   339  		continue
   340  		if x < y {
   341  			continue
   342  			break
   343  		}
   344  		switch x {
   345  		case y:
   346  			continue
   347  		default:
   348  			break
   349  		}
   350  		select {
   351  		case <-ch:
   352  			continue
   353  		}
   354  	}
   355  
   356  	var a []int
   357  	for _ = range a {
   358  		continue
   359  		if x < y {
   360  			continue
   361  			break
   362  		}
   363  		switch x {
   364  		case y:
   365  			continue
   366  		default:
   367  			break
   368  		}
   369  		select {
   370  		case <-ch:
   371  			continue
   372  		}
   373  	}
   374  }
   375  
   376  func returns0() {
   377  	return
   378  	return 0 /* ERROR no result values expected */
   379  }
   380  
   381  func returns1(x float64) (int, *float64) {
   382  	return 0, &x
   383  	return /* ERROR wrong number of return values */
   384  	return "foo" /* ERROR "cannot convert" */, x /* ERROR "cannot use .* in return statement" */
   385  	return /* ERROR wrong number of return values */ 0, &x, 1
   386  }
   387  
   388  func returns2() (a, b int) {
   389  	return
   390  	return 1, "foo" /* ERROR cannot convert */
   391  	return /* ERROR wrong number of return values */ 1, 2, 3
   392  	{
   393  		type a int
   394  		return 1, 2
   395  		return /* ERROR a not in scope at return */
   396  	}
   397  }
   398  
   399  func returns3() (_ int) {
   400  	return
   401  	{
   402  		var _ int // blank (_) identifiers never shadow since they are in no scope
   403  		return
   404  	}
   405  }
   406  
   407  func switches0() {
   408  	var x int
   409  
   410  	switch x {
   411  	}
   412  
   413  	switch x {
   414  	default:
   415  	default /* ERROR "multiple defaults" */ :
   416  	}
   417  
   418  	switch {
   419  	case 1  /* ERROR "cannot convert" */ :
   420  	}
   421  
   422  	true := "false"
   423  	_ = true
   424  	// A tagless switch is equivalent to the bool
   425          // constant true, not the identifier 'true'.
   426  	switch {
   427  	case "false" /* ERROR "cannot convert" */:
   428  	}
   429  
   430  	switch int32(x) {
   431  	case 1, 2:
   432  	case x /* ERROR "cannot compare" */ :
   433  	}
   434  
   435  	switch x {
   436  	case 1 /* ERROR "overflows" */ << 100:
   437  	}
   438  
   439  	switch x {
   440  	case 1:
   441  	case 1 /* ERROR "duplicate case" */ :
   442  	case ( /* ERROR "duplicate case" */ 1):
   443  	case 2, 3, 4:
   444  	case 5, 1 /* ERROR "duplicate case" */ :
   445  	}
   446  
   447  	switch uint64(x) {
   448  	case 1<<64 - 1:
   449  	case 1 /* ERROR duplicate case */ <<64 - 1:
   450  	case 2, 3, 4:
   451  	case 5, 1 /* ERROR duplicate case */ <<64 - 1:
   452  	}
   453  
   454  	var y32 float32
   455  	switch y32 {
   456  	case 1.1:
   457  	case 11/10: // integer division!
   458  	case 11. /* ERROR duplicate case */ /10:
   459  	case 2, 3.0, 4.1:
   460  	case 5.2, 1.10 /* ERROR duplicate case */ :
   461  	}
   462  
   463  	var y64 float64
   464  	switch y64 {
   465  	case 1.1:
   466  	case 11/10: // integer division!
   467  	case 11. /* ERROR duplicate case */ /10:
   468  	case 2, 3.0, 4.1:
   469  	case 5.2, 1.10 /* ERROR duplicate case */ :
   470  	}
   471  
   472  	var s string
   473  	switch s {
   474  	case "foo":
   475  	case "foo" /* ERROR duplicate case */ :
   476  	case "f" /* ERROR duplicate case */ + "oo":
   477  	case "abc", "def", "ghi":
   478  	case "jkl", "foo" /* ERROR duplicate case */ :
   479  	}
   480  
   481  	type T int
   482  	type F float64
   483  	type S string
   484  	type B bool
   485  	var i interface{}
   486  	switch i {
   487  	case nil:
   488  	case nil: // no duplicate detection
   489  	case (*int)(nil):
   490  	case (*int)(nil): // do duplicate detection
   491  	case 1:
   492  	case byte(1):
   493  	case int /* ERROR duplicate case */ (1):
   494  	case T(1):
   495  	case 1.0:
   496  	case F(1.0):
   497  	case F /* ERROR duplicate case */ (1.0):
   498  	case "hello":
   499  	case S("hello"):
   500  	case S /* ERROR duplicate case */ ("hello"):
   501  	case 1==1, B(false):
   502  	case false, B(2==2):
   503  	}
   504  
   505  	// switch on array
   506  	var a [3]int
   507  	switch a {
   508  	case [3]int{1, 2, 3}:
   509  	case [3]int{1, 2, 3}: // no duplicate detection
   510  	case [ /* ERROR "mismatched types */ 4]int{4, 5, 6}:
   511  	}
   512  
   513  	// switch on channel
   514  	var c1, c2 chan int
   515  	switch c1 {
   516  	case nil:
   517  	case c1:
   518  	case c2:
   519  	case c1, c2: // no duplicate detection
   520  	}
   521  }
   522  
   523  func switches1() {
   524  	fallthrough /* ERROR "fallthrough statement out of place" */
   525  
   526  	var x int
   527  	switch x {
   528  	case 0:
   529  		fallthrough /* ERROR "fallthrough statement out of place" */
   530  		break
   531  	case 1:
   532  		fallthrough
   533  	case 2:
   534  		fallthrough; ; ; // trailing empty statements are ok
   535  	case 3:
   536  	default:
   537  		fallthrough; ;
   538  	case 4:
   539  		fallthrough /* ERROR "fallthrough statement out of place" */
   540  	}
   541  
   542  	var y interface{}
   543  	switch y.(type) {
   544  	case int:
   545  		fallthrough /* ERROR "fallthrough statement out of place" */ ; ; ;
   546  	default:
   547  	}
   548  
   549  	switch x {
   550  	case 0:
   551  		if x == 0 {
   552  			fallthrough /* ERROR "fallthrough statement out of place" */
   553  		}
   554  	}
   555  
   556  	switch x {
   557  	case 0:
   558  		goto L1
   559  		L1: fallthrough; ;
   560  	case 1:
   561  		goto L2
   562  		goto L3
   563  		goto L4
   564  		L2: L3: L4: fallthrough
   565  	default:
   566  	}
   567  
   568  	switch x {
   569  	case 0:
   570  		goto L5
   571  		L5: fallthrough
   572  	default:
   573  		goto L6
   574  		goto L7
   575  		goto L8
   576  		L6: L7: L8: fallthrough /* ERROR "fallthrough statement out of place" */
   577  	}
   578  
   579  	switch x {
   580  	case 0:
   581  		fallthrough; ;
   582  	case 1:
   583  		{
   584  			fallthrough /* ERROR "fallthrough statement out of place" */
   585  		}
   586  	case 2:
   587  		fallthrough
   588  	case 3:
   589  		fallthrough /* ERROR "fallthrough statement out of place" */
   590  		{ /* empty block is not an empty statement */ }; ;
   591  	default:
   592  	}
   593  }
   594  
   595  func switches2() {
   596  	// untyped nil is not permitted as switch expression
   597  	switch nil /* ERROR "use of untyped nil" */ {
   598  	case 1, 2, "foo": // don't report additional errors here
   599  	}
   600  
   601  	// untyped constants are converted to default types
   602  	switch 1<<63-1 {
   603  	}
   604  	switch 1 /* ERROR "overflows int" */ << 63 {
   605  	}
   606  	var x int
   607  	switch 1.0 {
   608  	case 1.0, 2.0, x /* ERROR "mismatched types int and float64" */ :
   609  	}
   610  	switch x {
   611  	case 1.0:
   612  	}
   613  
   614  	// untyped bools become of type bool
   615  	type B bool
   616  	var b B = true
   617  	switch x == x {
   618  	case b /* ERROR "mismatched types B and bool" */ :
   619  	}
   620  	switch {
   621  	case b /* ERROR "mismatched types B and bool" */ :
   622  	}
   623  }
   624  
   625  func issue11667() {
   626  	switch 9223372036854775808 /* ERROR "overflows int" */ {
   627  	}
   628  	switch 9223372036854775808 /* ERROR "overflows int" */ {
   629  	case 9223372036854775808:
   630  	}
   631  	var x int
   632  	switch x {
   633  	case 9223372036854775808 /* ERROR "overflows int" */ :
   634  	}
   635  	var y float64
   636  	switch y {
   637  	case 9223372036854775808:
   638  	}
   639  }
   640  
   641  func issue11687() {
   642  	f := func() (_, _ int) { return }
   643  	switch f /* ERROR "2-valued f" */ () {
   644  	}
   645  	var x int
   646  	switch f /* ERROR "2-valued f" */ () {
   647  	case x:
   648  	}
   649  	switch x {
   650  	case f /* ERROR "2-valued f" */ ():
   651  	}
   652  }
   653  
   654  type I interface {
   655  	m()
   656  }
   657  
   658  type I2 interface {
   659  	m(int)
   660  }
   661  
   662  type T struct{}
   663  type T1 struct{}
   664  type T2 struct{}
   665  
   666  func (T) m() {}
   667  func (T2) m(int) {}
   668  
   669  func typeswitches() {
   670  	var i int
   671  	var x interface{}
   672  
   673  	switch x.(type) {}
   674  	switch (x /* ERROR "outside type switch" */ .(type)) {}
   675  
   676  	switch x.(type) {
   677  	default:
   678  	default /* ERROR "multiple defaults" */ :
   679  	}
   680  
   681  	switch x /* ERROR "declared but not used" */ := x.(type) {}
   682  	switch _ /* ERROR "no new variable on left side of :=" */ := x.(type) {}
   683  
   684  	switch x := x.(type) {
   685  	case int:
   686  		var y int = x
   687  		_ = y
   688  	}
   689  
   690  	switch x := i /* ERROR "not an interface" */ .(type) {}
   691  
   692  	switch t := x.(type) {
   693  	case nil:
   694  		var v bool = t /* ERROR "cannot use .* in variable declaration" */
   695  		_ = v
   696  	case int:
   697  		var v int = t
   698  		_ = v
   699  	case float32, complex64:
   700  		var v float32 = t /* ERROR "cannot use .* in variable declaration" */
   701  		_ = v
   702  	default:
   703  		var v float32 = t /* ERROR "cannot use .* in variable declaration" */
   704  		_ = v
   705  	}
   706  
   707  	var t I
   708  	switch t.(type) {
   709  	case T:
   710  	case T1 /* ERROR "missing method m" */ :
   711  	case T2 /* ERROR "wrong type for method m" */ :
   712  	case I2 /* STRICT "wrong type for method m" */ : // only an error in strict mode (issue 8561)
   713  	}
   714  }
   715  
   716  // Test that each case clause uses the correct type of the variable
   717  // declared by the type switch (issue 5504).
   718  func typeswitch0() {
   719  	switch y := interface{}(nil).(type) {
   720  	case int:
   721  		func() int { return y + 0 }()
   722  	case float32:
   723  		func() float32 { return y }()
   724  	}
   725  }
   726  
   727  // Test correct scope setup.
   728  // (no redeclaration errors expected in the type switch)
   729  func typeswitch1() {
   730  	var t I
   731  	switch t := t; t := t.(type) {
   732  	case nil:
   733  		var _ I = t
   734  	case T:
   735  		var _ T = t
   736  	default:
   737  		var _ I = t
   738  	}
   739  }
   740  
   741  // Test correct typeswitch against interface types.
   742  type A interface { a() }
   743  type B interface { b() }
   744  type C interface { a(int) }
   745  
   746  func typeswitch2() {
   747  	switch A(nil).(type) {
   748  	case A:
   749  	case B:
   750  	case C /* STRICT "cannot have dynamic type" */: // only an error in strict mode (issue 8561)
   751  	}
   752  }
   753  
   754  func typeswitch3(x interface{}) {
   755  	switch x.(type) {
   756  	case int:
   757  	case float64:
   758  	case int /* ERROR duplicate case */ :
   759  	}
   760  
   761  	switch x.(type) {
   762  	case nil:
   763  	case int:
   764  	case nil /* ERROR duplicate case */ , nil /* ERROR duplicate case */ :
   765  	}
   766  
   767  	type F func(int)
   768  	switch x.(type) {
   769  	case nil:
   770  	case int, func(int):
   771  	case float32, func /* ERROR duplicate case */ (x int):
   772  	case F:
   773  	}
   774  }
   775  
   776  func fors1() {
   777  	for {}
   778  	var i string
   779  	_ = i
   780  	for i := 0; i < 10; i++ {}
   781  	for i := 0; i < 10; j /* ERROR cannot declare */ := 0 {}
   782  }
   783  
   784  func rangeloops1() {
   785  	var (
   786  		x int
   787  		a [10]float32
   788  		b []string
   789  		p *[10]complex128
   790  		pp **[10]complex128
   791  		s string
   792  		m map[int]bool
   793  		c chan int
   794  		sc chan<- int
   795  		rc <-chan int
   796  	)
   797  
   798  	for range x /* ERROR "cannot range over" */ {}
   799  	for _ = range x /* ERROR "cannot range over" */ {}
   800  	for i := range x /* ERROR "cannot range over" */ {}
   801  
   802  	for range a {}
   803  	for i := range a {
   804  		var ii int
   805  		ii = i
   806  		_ = ii
   807  	}
   808  	for i, x := range a {
   809  		var ii int
   810  		ii = i
   811  		_ = ii
   812  		var xx float64
   813  		xx = x /* ERROR "cannot use .* in assignment" */
   814  		_ = xx
   815  	}
   816  	var ii int
   817  	var xx float32
   818  	for ii, xx = range a {}
   819  	_, _ = ii, xx
   820  
   821  	for range b {}
   822  	for i := range b {
   823  		var ii int
   824  		ii = i
   825  		_ = ii
   826  	}
   827  	for i, x := range b {
   828  		var ii int
   829  		ii = i
   830  		_ = ii
   831  		var xx string
   832  		xx = x
   833  		_ = xx
   834  	}
   835  
   836  	for range s {}
   837  	for i := range s {
   838  		var ii int
   839  		ii = i
   840  		_ = ii
   841  	}
   842  	for i, x := range s {
   843  		var ii int
   844  		ii = i
   845  		_ = ii
   846  		var xx rune
   847  		xx = x
   848  		_ = xx
   849  	}
   850  
   851  	for range p {}
   852  	for _, x := range p {
   853  		var xx complex128
   854  		xx = x
   855  		_ = xx
   856  	}
   857  
   858  	for range pp /* ERROR "cannot range over" */ {}
   859  	for _, x := range pp /* ERROR "cannot range over" */ {}
   860  
   861  	for range m {}
   862  	for k := range m {
   863  		var kk int32
   864  		kk = k /* ERROR "cannot use .* in assignment" */
   865  		_ = kk
   866  	}
   867  	for k, v := range m {
   868  		var kk int
   869  		kk = k
   870  		_ = kk
   871  		if v {}
   872  	}
   873  
   874  	for range c {}
   875  	for _, _ /* ERROR "only one iteration variable" */ = range c {}
   876  	for e := range c {
   877  		var ee int
   878  		ee = e
   879  		_ = ee
   880  	}
   881  	for _ = range sc /* ERROR "cannot range over send-only channel" */ {}
   882  	for _ = range rc {}
   883  
   884  	// constant strings
   885  	const cs = "foo"
   886  	for range cs {}
   887  	for range "" {}
   888  	for i, x := range cs { _, _ = i, x }
   889  	for i, x := range "" {
   890  		var ii int
   891  		ii = i
   892  		_ = ii
   893  		var xx rune
   894  		xx = x
   895  		_ = xx
   896  	}
   897  }
   898  
   899  func rangeloops2() {
   900  	type I int
   901  	type R rune
   902  
   903  	var a [10]int
   904  	var i I
   905  	_ = i
   906  	for i /* ERROR cannot use .* in assignment */ = range a {}
   907  	for i /* ERROR cannot use .* in assignment */ = range &a {}
   908  	for i /* ERROR cannot use .* in assignment */ = range a[:] {}
   909  
   910  	var s string
   911  	var r R
   912  	_ = r
   913  	for i /* ERROR cannot use .* in assignment */ = range s {}
   914  	for i /* ERROR cannot use .* in assignment */ = range "foo" {}
   915  	for _, r /* ERROR cannot use .* in assignment */ = range s {}
   916  	for _, r /* ERROR cannot use .* in assignment */ = range "foo" {}
   917  }
   918  
   919  func issue6766b() {
   920  	for _ := /* ERROR no new variables */ range "" {}
   921  	for a, a /* ERROR redeclared */ := range "" { _ = a }
   922  	var a int
   923  	_ = a
   924  	for a, a /* ERROR redeclared */ := range []int{1, 2, 3} { _ = a }
   925  }
   926  
   927  // Test that despite errors in the range clause,
   928  // the loop body is still type-checked (and thus
   929  // errors reported).
   930  func issue10148() {
   931  	for y /* ERROR declared but not used */ := range "" {
   932  		_ = "" /* ERROR cannot convert */ + 1
   933  	}
   934  	for range 1 /* ERROR cannot range over 1 */ {
   935  		_ = "" /* ERROR cannot convert */ + 1
   936  	}
   937  	for y := range 1 /* ERROR cannot range over 1 */ {
   938  		_ = "" /* ERROR cannot convert */ + 1
   939  	}
   940  }
   941  
   942  func labels0() {
   943  	goto L0
   944  	goto L1
   945  	L0:
   946  	L1:
   947  	L1 /* ERROR "already declared" */ :
   948  	if true {
   949  		goto L2
   950  		L2:
   951  		L0 /* ERROR "already declared" */ :
   952  	}
   953  	_ = func() {
   954  		goto L0
   955  		goto L1
   956  		goto L2
   957  		L0:
   958  		L1:
   959  		L2:
   960  	}
   961  }
   962  
   963  func expression_statements(ch chan int) {
   964  	expression_statements(ch)
   965  	<-ch
   966  	println()
   967  
   968  	0 /* ERROR "not used" */
   969  	1 /* ERROR "not used" */ +2
   970  	cap /* ERROR "not used" */ (ch)
   971  	println /* ERROR "must be called" */
   972  }