Home | History | Annotate | Download | only in testdata
      1 // Copyright 2013 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 // +build ignore
      6 
      7 // This file contains tests for the dead code checker.
      8 
      9 package testdata
     10 
     11 type T int
     12 
     13 var x interface{}
     14 var c chan int
     15 
     16 func external() int // ok
     17 
     18 func _() int {
     19 }
     20 
     21 func _() int {
     22 	print(1)
     23 }
     24 
     25 func _() int {
     26 	print(1)
     27 	return 2
     28 	println() // ERROR "unreachable code"
     29 }
     30 
     31 func _() int {
     32 L:
     33 	print(1)
     34 	goto L
     35 	println() // ERROR "unreachable code"
     36 }
     37 
     38 func _() int {
     39 	print(1)
     40 	panic(2)
     41 	println() // ERROR "unreachable code"
     42 }
     43 
     44 // but only builtin panic
     45 func _() int {
     46 	var panic = func(int) {}
     47 	print(1)
     48 	panic(2)
     49 	println() // ok
     50 }
     51 
     52 func _() int {
     53 	{
     54 		print(1)
     55 		return 2
     56 		println() // ERROR "unreachable code"
     57 	}
     58 	println() // ok
     59 }
     60 
     61 func _() int {
     62 	{
     63 		print(1)
     64 		return 2
     65 	}
     66 	println() // ERROR "unreachable code"
     67 }
     68 
     69 func _() int {
     70 L:
     71 	{
     72 		print(1)
     73 		goto L
     74 		println() // ERROR "unreachable code"
     75 	}
     76 	println() // ok
     77 }
     78 
     79 func _() int {
     80 L:
     81 	{
     82 		print(1)
     83 		goto L
     84 	}
     85 	println() // ERROR "unreachable code"
     86 }
     87 
     88 func _() int {
     89 	print(1)
     90 	{
     91 		panic(2)
     92 	}
     93 }
     94 
     95 func _() int {
     96 	print(1)
     97 	{
     98 		panic(2)
     99 		println() // ERROR "unreachable code"
    100 	}
    101 }
    102 
    103 func _() int {
    104 	print(1)
    105 	{
    106 		panic(2)
    107 	}
    108 	println() // ERROR "unreachable code"
    109 }
    110 
    111 func _() int {
    112 	print(1)
    113 	return 2
    114 	{ // ERROR "unreachable code"
    115 	}
    116 }
    117 
    118 func _() int {
    119 L:
    120 	print(1)
    121 	goto L
    122 	{ // ERROR "unreachable code"
    123 	}
    124 }
    125 
    126 func _() int {
    127 	print(1)
    128 	panic(2)
    129 	{ // ERROR "unreachable code"
    130 	}
    131 }
    132 
    133 func _() int {
    134 	{
    135 		print(1)
    136 		return 2
    137 		{ // ERROR "unreachable code"
    138 		}
    139 	}
    140 }
    141 
    142 func _() int {
    143 L:
    144 	{
    145 		print(1)
    146 		goto L
    147 		{ // ERROR "unreachable code"
    148 		}
    149 	}
    150 }
    151 
    152 func _() int {
    153 	print(1)
    154 	{
    155 		panic(2)
    156 		{ // ERROR "unreachable code"
    157 		}
    158 	}
    159 }
    160 
    161 func _() int {
    162 	{
    163 		print(1)
    164 		return 2
    165 	}
    166 	{ // ERROR "unreachable code"
    167 	}
    168 }
    169 
    170 func _() int {
    171 L:
    172 	{
    173 		print(1)
    174 		goto L
    175 	}
    176 	{ // ERROR "unreachable code"
    177 	}
    178 }
    179 
    180 func _() int {
    181 	print(1)
    182 	{
    183 		panic(2)
    184 	}
    185 	{ // ERROR "unreachable code"
    186 	}
    187 }
    188 
    189 func _() int {
    190 	print(1)
    191 	if x == nil {
    192 		panic(2)
    193 	} else {
    194 		panic(3)
    195 	}
    196 	println() // ERROR "unreachable code"
    197 }
    198 
    199 func _() int {
    200 L:
    201 	print(1)
    202 	if x == nil {
    203 		panic(2)
    204 	} else {
    205 		goto L
    206 	}
    207 	println() // ERROR "unreachable code"
    208 }
    209 
    210 func _() int {
    211 L:
    212 	print(1)
    213 	if x == nil {
    214 		panic(2)
    215 	} else if x == 1 {
    216 		return 0
    217 	} else if x != 2 {
    218 		panic(3)
    219 	} else {
    220 		goto L
    221 	}
    222 	println() // ERROR "unreachable code"
    223 }
    224 
    225 // if-else chain missing final else is not okay, even if the
    226 // conditions cover every possible case.
    227 
    228 func _() int {
    229 	print(1)
    230 	if x == nil {
    231 		panic(2)
    232 	} else if x != nil {
    233 		panic(3)
    234 	}
    235 	println() // ok
    236 }
    237 
    238 func _() int {
    239 	print(1)
    240 	if x == nil {
    241 		panic(2)
    242 	}
    243 	println() // ok
    244 }
    245 
    246 func _() int {
    247 L:
    248 	print(1)
    249 	if x == nil {
    250 		panic(2)
    251 	} else if x == 1 {
    252 		return 0
    253 	} else if x != 1 {
    254 		panic(3)
    255 	}
    256 	println() // ok
    257 }
    258 
    259 func _() int {
    260 	print(1)
    261 	for {
    262 	}
    263 	println() // ERROR "unreachable code"
    264 }
    265 
    266 func _() int {
    267 	for {
    268 		for {
    269 			break
    270 		}
    271 	}
    272 	println() // ERROR "unreachable code"
    273 }
    274 
    275 func _() int {
    276 	for {
    277 		for {
    278 			break
    279 			println() // ERROR "unreachable code"
    280 		}
    281 	}
    282 }
    283 
    284 func _() int {
    285 	for {
    286 		for {
    287 			continue
    288 			println() // ERROR "unreachable code"
    289 		}
    290 	}
    291 }
    292 
    293 func _() int {
    294 	for {
    295 	L:
    296 		for {
    297 			break L
    298 		}
    299 	}
    300 	println() // ERROR "unreachable code"
    301 }
    302 
    303 func _() int {
    304 	print(1)
    305 	for {
    306 		break
    307 	}
    308 	println() // ok
    309 }
    310 
    311 func _() int {
    312 	for {
    313 		for {
    314 		}
    315 		break // ERROR "unreachable code"
    316 	}
    317 	println() // ok
    318 }
    319 
    320 func _() int {
    321 L:
    322 	for {
    323 		for {
    324 			break L
    325 		}
    326 	}
    327 	println() // ok
    328 }
    329 
    330 func _() int {
    331 	print(1)
    332 	for x == nil {
    333 	}
    334 	println() // ok
    335 }
    336 
    337 func _() int {
    338 	for x == nil {
    339 		for {
    340 			break
    341 		}
    342 	}
    343 	println() // ok
    344 }
    345 
    346 func _() int {
    347 	for x == nil {
    348 	L:
    349 		for {
    350 			break L
    351 		}
    352 	}
    353 	println() // ok
    354 }
    355 
    356 func _() int {
    357 	print(1)
    358 	for true {
    359 	}
    360 	println() // ok
    361 }
    362 
    363 func _() int {
    364 	for true {
    365 		for {
    366 			break
    367 		}
    368 	}
    369 	println() // ok
    370 }
    371 
    372 func _() int {
    373 	for true {
    374 	L:
    375 		for {
    376 			break L
    377 		}
    378 	}
    379 	println() // ok
    380 }
    381 
    382 func _() int {
    383 	print(1)
    384 	select {}
    385 	println() // ERROR "unreachable code"
    386 }
    387 
    388 func _() int {
    389 	print(1)
    390 	select {
    391 	case <-c:
    392 		print(2)
    393 		panic("abc")
    394 		println() // ERROR "unreachable code"
    395 	}
    396 }
    397 
    398 func _() int {
    399 	print(1)
    400 	select {
    401 	case <-c:
    402 		print(2)
    403 		panic("abc")
    404 	}
    405 	println() // ERROR "unreachable code"
    406 }
    407 
    408 func _() int {
    409 	print(1)
    410 	select {
    411 	case <-c:
    412 		print(2)
    413 		for {
    414 		}
    415 		println() // ERROR "unreachable code"
    416 	}
    417 }
    418 
    419 func _() int {
    420 	print(1)
    421 	select {
    422 	case <-c:
    423 		print(2)
    424 		for {
    425 		}
    426 	}
    427 	println() // ERROR "unreachable code"
    428 }
    429 
    430 func _() int {
    431 L:
    432 	print(1)
    433 	select {
    434 	case <-c:
    435 		print(2)
    436 		panic("abc")
    437 		println() // ERROR "unreachable code"
    438 	case c <- 1:
    439 		print(2)
    440 		goto L
    441 		println() // ERROR "unreachable code"
    442 	}
    443 }
    444 
    445 func _() int {
    446 L:
    447 	print(1)
    448 	select {
    449 	case <-c:
    450 		print(2)
    451 		panic("abc")
    452 	case c <- 1:
    453 		print(2)
    454 		goto L
    455 	}
    456 	println() // ERROR "unreachable code"
    457 }
    458 
    459 func _() int {
    460 	print(1)
    461 	select {
    462 	case <-c:
    463 		print(2)
    464 		panic("abc")
    465 		println() // ERROR "unreachable code"
    466 	default:
    467 		select {}
    468 		println() // ERROR "unreachable code"
    469 	}
    470 }
    471 
    472 func _() int {
    473 	print(1)
    474 	select {
    475 	case <-c:
    476 		print(2)
    477 		panic("abc")
    478 	default:
    479 		select {}
    480 	}
    481 	println() // ERROR "unreachable code"
    482 }
    483 
    484 func _() int {
    485 	print(1)
    486 	select {
    487 	case <-c:
    488 		print(2)
    489 	}
    490 	println() // ok
    491 }
    492 
    493 func _() int {
    494 L:
    495 	print(1)
    496 	select {
    497 	case <-c:
    498 		print(2)
    499 		panic("abc")
    500 		goto L // ERROR "unreachable code"
    501 	case c <- 1:
    502 		print(2)
    503 	}
    504 	println() // ok
    505 }
    506 
    507 func _() int {
    508 	print(1)
    509 	select {
    510 	case <-c:
    511 		print(2)
    512 		panic("abc")
    513 	default:
    514 		print(2)
    515 	}
    516 	println() // ok
    517 }
    518 
    519 func _() int {
    520 	print(1)
    521 	select {
    522 	default:
    523 		break
    524 	}
    525 	println() // ok
    526 }
    527 
    528 func _() int {
    529 	print(1)
    530 	select {
    531 	case <-c:
    532 		print(2)
    533 		panic("abc")
    534 		break // ERROR "unreachable code"
    535 	}
    536 	println() // ok
    537 }
    538 
    539 func _() int {
    540 	print(1)
    541 L:
    542 	select {
    543 	case <-c:
    544 		print(2)
    545 		for {
    546 			break L
    547 		}
    548 	}
    549 	println() // ok
    550 }
    551 
    552 func _() int {
    553 	print(1)
    554 L:
    555 	select {
    556 	case <-c:
    557 		print(2)
    558 		panic("abc")
    559 	case c <- 1:
    560 		print(2)
    561 		break L
    562 	}
    563 	println() // ok
    564 }
    565 
    566 func _() int {
    567 	print(1)
    568 	select {
    569 	case <-c:
    570 		print(1)
    571 		panic("abc")
    572 	default:
    573 		select {}
    574 		break // ERROR "unreachable code"
    575 	}
    576 	println() // ok
    577 }
    578 
    579 func _() int {
    580 	print(1)
    581 	switch x {
    582 	case 1:
    583 		print(2)
    584 		panic(3)
    585 		println() // ERROR "unreachable code"
    586 	default:
    587 		return 4
    588 		println() // ERROR "unreachable code"
    589 	}
    590 }
    591 
    592 func _() int {
    593 	print(1)
    594 	switch x {
    595 	case 1:
    596 		print(2)
    597 		panic(3)
    598 	default:
    599 		return 4
    600 	}
    601 	println() // ERROR "unreachable code"
    602 }
    603 
    604 func _() int {
    605 	print(1)
    606 	switch x {
    607 	default:
    608 		return 4
    609 		println() // ERROR "unreachable code"
    610 	case 1:
    611 		print(2)
    612 		panic(3)
    613 		println() // ERROR "unreachable code"
    614 	}
    615 }
    616 
    617 func _() int {
    618 	print(1)
    619 	switch x {
    620 	default:
    621 		return 4
    622 	case 1:
    623 		print(2)
    624 		panic(3)
    625 	}
    626 	println() // ERROR "unreachable code"
    627 }
    628 
    629 func _() int {
    630 	print(1)
    631 	switch x {
    632 	case 1:
    633 		print(2)
    634 		fallthrough
    635 	default:
    636 		return 4
    637 		println() // ERROR "unreachable code"
    638 	}
    639 }
    640 
    641 func _() int {
    642 	print(1)
    643 	switch x {
    644 	case 1:
    645 		print(2)
    646 		fallthrough
    647 	default:
    648 		return 4
    649 	}
    650 	println() // ERROR "unreachable code"
    651 }
    652 
    653 func _() int {
    654 	print(1)
    655 	switch {
    656 	}
    657 	println() // ok
    658 }
    659 
    660 func _() int {
    661 	print(1)
    662 	switch x {
    663 	case 1:
    664 		print(2)
    665 		panic(3)
    666 	case 2:
    667 		return 4
    668 	}
    669 	println() // ok
    670 }
    671 
    672 func _() int {
    673 	print(1)
    674 	switch x {
    675 	case 2:
    676 		return 4
    677 	case 1:
    678 		print(2)
    679 		panic(3)
    680 	}
    681 	println() // ok
    682 }
    683 
    684 func _() int {
    685 	print(1)
    686 	switch x {
    687 	case 1:
    688 		print(2)
    689 		fallthrough
    690 	case 2:
    691 		return 4
    692 	}
    693 	println() // ok
    694 }
    695 
    696 func _() int {
    697 	print(1)
    698 	switch x {
    699 	case 1:
    700 		print(2)
    701 		panic(3)
    702 	}
    703 	println() // ok
    704 }
    705 
    706 func _() int {
    707 	print(1)
    708 L:
    709 	switch x {
    710 	case 1:
    711 		print(2)
    712 		panic(3)
    713 		break L // ERROR "unreachable code"
    714 	default:
    715 		return 4
    716 	}
    717 	println() // ok
    718 }
    719 
    720 func _() int {
    721 	print(1)
    722 	switch x {
    723 	default:
    724 		return 4
    725 		break // ERROR "unreachable code"
    726 	case 1:
    727 		print(2)
    728 		panic(3)
    729 	}
    730 	println() // ok
    731 }
    732 
    733 func _() int {
    734 	print(1)
    735 L:
    736 	switch x {
    737 	case 1:
    738 		print(2)
    739 		for {
    740 			break L
    741 		}
    742 	default:
    743 		return 4
    744 	}
    745 	println() // ok
    746 }
    747 
    748 func _() int {
    749 	print(1)
    750 	switch x.(type) {
    751 	case int:
    752 		print(2)
    753 		panic(3)
    754 		println() // ERROR "unreachable code"
    755 	default:
    756 		return 4
    757 		println() // ERROR "unreachable code"
    758 	}
    759 }
    760 
    761 func _() int {
    762 	print(1)
    763 	switch x.(type) {
    764 	case int:
    765 		print(2)
    766 		panic(3)
    767 	default:
    768 		return 4
    769 	}
    770 	println() // ERROR "unreachable code"
    771 }
    772 
    773 func _() int {
    774 	print(1)
    775 	switch x.(type) {
    776 	default:
    777 		return 4
    778 		println() // ERROR "unreachable code"
    779 	case int:
    780 		print(2)
    781 		panic(3)
    782 		println() // ERROR "unreachable code"
    783 	}
    784 }
    785 
    786 func _() int {
    787 	print(1)
    788 	switch x.(type) {
    789 	default:
    790 		return 4
    791 	case int:
    792 		print(2)
    793 		panic(3)
    794 	}
    795 	println() // ERROR "unreachable code"
    796 }
    797 
    798 func _() int {
    799 	print(1)
    800 	switch x.(type) {
    801 	case int:
    802 		print(2)
    803 		fallthrough
    804 	default:
    805 		return 4
    806 		println() // ERROR "unreachable code"
    807 	}
    808 }
    809 
    810 func _() int {
    811 	print(1)
    812 	switch x.(type) {
    813 	case int:
    814 		print(2)
    815 		fallthrough
    816 	default:
    817 		return 4
    818 	}
    819 	println() // ERROR "unreachable code"
    820 }
    821 
    822 func _() int {
    823 	print(1)
    824 	switch {
    825 	}
    826 	println() // ok
    827 }
    828 
    829 func _() int {
    830 	print(1)
    831 	switch x.(type) {
    832 	case int:
    833 		print(2)
    834 		panic(3)
    835 	case float64:
    836 		return 4
    837 	}
    838 	println() // ok
    839 }
    840 
    841 func _() int {
    842 	print(1)
    843 	switch x.(type) {
    844 	case float64:
    845 		return 4
    846 	case int:
    847 		print(2)
    848 		panic(3)
    849 	}
    850 	println() // ok
    851 }
    852 
    853 func _() int {
    854 	print(1)
    855 	switch x.(type) {
    856 	case int:
    857 		print(2)
    858 		fallthrough
    859 	case float64:
    860 		return 4
    861 	}
    862 	println() // ok
    863 }
    864 
    865 func _() int {
    866 	print(1)
    867 	switch x.(type) {
    868 	case int:
    869 		print(2)
    870 		panic(3)
    871 	}
    872 	println() // ok
    873 }
    874 
    875 func _() int {
    876 	print(1)
    877 L:
    878 	switch x.(type) {
    879 	case int:
    880 		print(2)
    881 		panic(3)
    882 		break L // ERROR "unreachable code"
    883 	default:
    884 		return 4
    885 	}
    886 	println() // ok
    887 }
    888 
    889 func _() int {
    890 	print(1)
    891 	switch x.(type) {
    892 	default:
    893 		return 4
    894 		break // ERROR "unreachable code"
    895 	case int:
    896 		print(2)
    897 		panic(3)
    898 	}
    899 	println() // ok
    900 }
    901 
    902 func _() int {
    903 	print(1)
    904 L:
    905 	switch x.(type) {
    906 	case int:
    907 		print(2)
    908 		for {
    909 			break L
    910 		}
    911 	default:
    912 		return 4
    913 	}
    914 	println() // ok
    915 }
    916 
    917 // again, but without the leading print(1).
    918 // testing that everything works when the terminating statement is first.
    919 
    920 func _() int {
    921 	println() // ok
    922 }
    923 
    924 func _() int {
    925 	return 2
    926 	println() // ERROR "unreachable code"
    927 }
    928 
    929 func _() int {
    930 L:
    931 	goto L
    932 	println() // ERROR "unreachable code"
    933 }
    934 
    935 func _() int {
    936 	panic(2)
    937 	println() // ERROR "unreachable code"
    938 }
    939 
    940 // but only builtin panic
    941 func _() int {
    942 	var panic = func(int) {}
    943 	panic(2)
    944 	println() // ok
    945 }
    946 
    947 func _() int {
    948 	{
    949 		return 2
    950 		println() // ERROR "unreachable code"
    951 	}
    952 }
    953 
    954 func _() int {
    955 	{
    956 		return 2
    957 	}
    958 	println() // ERROR "unreachable code"
    959 }
    960 
    961 func _() int {
    962 L:
    963 	{
    964 		goto L
    965 		println() // ERROR "unreachable code"
    966 	}
    967 }
    968 
    969 func _() int {
    970 L:
    971 	{
    972 		goto L
    973 	}
    974 	println() // ERROR "unreachable code"
    975 }
    976 
    977 func _() int {
    978 	{
    979 		panic(2)
    980 		println() // ERROR "unreachable code"
    981 	}
    982 }
    983 
    984 func _() int {
    985 	{
    986 		panic(2)
    987 	}
    988 	println() // ERROR "unreachable code"
    989 }
    990 
    991 func _() int {
    992 	return 2
    993 	{ // ERROR "unreachable code"
    994 	}
    995 	println() // ok
    996 }
    997 
    998 func _() int {
    999 L:
   1000 	goto L
   1001 	{ // ERROR "unreachable code"
   1002 	}
   1003 	println() // ok
   1004 }
   1005 
   1006 func _() int {
   1007 	panic(2)
   1008 	{ // ERROR "unreachable code"
   1009 	}
   1010 	println() // ok
   1011 }
   1012 
   1013 func _() int {
   1014 	{
   1015 		return 2
   1016 		{ // ERROR "unreachable code"
   1017 		}
   1018 	}
   1019 	println() // ok
   1020 }
   1021 
   1022 func _() int {
   1023 L:
   1024 	{
   1025 		goto L
   1026 		{ // ERROR "unreachable code"
   1027 		}
   1028 	}
   1029 	println() // ok
   1030 }
   1031 
   1032 func _() int {
   1033 	{
   1034 		panic(2)
   1035 		{ // ERROR "unreachable code"
   1036 		}
   1037 	}
   1038 	println() // ok
   1039 }
   1040 
   1041 func _() int {
   1042 	{
   1043 		return 2
   1044 	}
   1045 	{ // ERROR "unreachable code"
   1046 	}
   1047 	println() // ok
   1048 }
   1049 
   1050 func _() int {
   1051 L:
   1052 	{
   1053 		goto L
   1054 	}
   1055 	{ // ERROR "unreachable code"
   1056 	}
   1057 	println() // ok
   1058 }
   1059 
   1060 func _() int {
   1061 	{
   1062 		panic(2)
   1063 	}
   1064 	{ // ERROR "unreachable code"
   1065 	}
   1066 	println() // ok
   1067 }
   1068 
   1069 // again, with func literals
   1070 
   1071 var _ = func() int {
   1072 }
   1073 
   1074 var _ = func() int {
   1075 	print(1)
   1076 }
   1077 
   1078 var _ = func() int {
   1079 	print(1)
   1080 	return 2
   1081 	println() // ERROR "unreachable code"
   1082 }
   1083 
   1084 var _ = func() int {
   1085 L:
   1086 	print(1)
   1087 	goto L
   1088 	println() // ERROR "unreachable code"
   1089 }
   1090 
   1091 var _ = func() int {
   1092 	print(1)
   1093 	panic(2)
   1094 	println() // ERROR "unreachable code"
   1095 }
   1096 
   1097 // but only builtin panic
   1098 var _ = func() int {
   1099 	var panic = func(int) {}
   1100 	print(1)
   1101 	panic(2)
   1102 	println() // ok
   1103 }
   1104 
   1105 var _ = func() int {
   1106 	{
   1107 		print(1)
   1108 		return 2
   1109 		println() // ERROR "unreachable code"
   1110 	}
   1111 	println() // ok
   1112 }
   1113 
   1114 var _ = func() int {
   1115 	{
   1116 		print(1)
   1117 		return 2
   1118 	}
   1119 	println() // ERROR "unreachable code"
   1120 }
   1121 
   1122 var _ = func() int {
   1123 L:
   1124 	{
   1125 		print(1)
   1126 		goto L
   1127 		println() // ERROR "unreachable code"
   1128 	}
   1129 	println() // ok
   1130 }
   1131 
   1132 var _ = func() int {
   1133 L:
   1134 	{
   1135 		print(1)
   1136 		goto L
   1137 	}
   1138 	println() // ERROR "unreachable code"
   1139 }
   1140 
   1141 var _ = func() int {
   1142 	print(1)
   1143 	{
   1144 		panic(2)
   1145 	}
   1146 }
   1147 
   1148 var _ = func() int {
   1149 	print(1)
   1150 	{
   1151 		panic(2)
   1152 		println() // ERROR "unreachable code"
   1153 	}
   1154 }
   1155 
   1156 var _ = func() int {
   1157 	print(1)
   1158 	{
   1159 		panic(2)
   1160 	}
   1161 	println() // ERROR "unreachable code"
   1162 }
   1163 
   1164 var _ = func() int {
   1165 	print(1)
   1166 	return 2
   1167 	{ // ERROR "unreachable code"
   1168 	}
   1169 }
   1170 
   1171 var _ = func() int {
   1172 L:
   1173 	print(1)
   1174 	goto L
   1175 	{ // ERROR "unreachable code"
   1176 	}
   1177 }
   1178 
   1179 var _ = func() int {
   1180 	print(1)
   1181 	panic(2)
   1182 	{ // ERROR "unreachable code"
   1183 	}
   1184 }
   1185 
   1186 var _ = func() int {
   1187 	{
   1188 		print(1)
   1189 		return 2
   1190 		{ // ERROR "unreachable code"
   1191 		}
   1192 	}
   1193 }
   1194 
   1195 var _ = func() int {
   1196 L:
   1197 	{
   1198 		print(1)
   1199 		goto L
   1200 		{ // ERROR "unreachable code"
   1201 		}
   1202 	}
   1203 }
   1204 
   1205 var _ = func() int {
   1206 	print(1)
   1207 	{
   1208 		panic(2)
   1209 		{ // ERROR "unreachable code"
   1210 		}
   1211 	}
   1212 }
   1213 
   1214 var _ = func() int {
   1215 	{
   1216 		print(1)
   1217 		return 2
   1218 	}
   1219 	{ // ERROR "unreachable code"
   1220 	}
   1221 }
   1222 
   1223 var _ = func() int {
   1224 L:
   1225 	{
   1226 		print(1)
   1227 		goto L
   1228 	}
   1229 	{ // ERROR "unreachable code"
   1230 	}
   1231 }
   1232 
   1233 var _ = func() int {
   1234 	print(1)
   1235 	{
   1236 		panic(2)
   1237 	}
   1238 	{ // ERROR "unreachable code"
   1239 	}
   1240 }
   1241 
   1242 var _ = func() int {
   1243 	print(1)
   1244 	if x == nil {
   1245 		panic(2)
   1246 	} else {
   1247 		panic(3)
   1248 	}
   1249 	println() // ERROR "unreachable code"
   1250 }
   1251 
   1252 var _ = func() int {
   1253 L:
   1254 	print(1)
   1255 	if x == nil {
   1256 		panic(2)
   1257 	} else {
   1258 		goto L
   1259 	}
   1260 	println() // ERROR "unreachable code"
   1261 }
   1262 
   1263 var _ = func() int {
   1264 L:
   1265 	print(1)
   1266 	if x == nil {
   1267 		panic(2)
   1268 	} else if x == 1 {
   1269 		return 0
   1270 	} else if x != 2 {
   1271 		panic(3)
   1272 	} else {
   1273 		goto L
   1274 	}
   1275 	println() // ERROR "unreachable code"
   1276 }
   1277 
   1278 // if-else chain missing final else is not okay, even if the
   1279 // conditions cover every possible case.
   1280 
   1281 var _ = func() int {
   1282 	print(1)
   1283 	if x == nil {
   1284 		panic(2)
   1285 	} else if x != nil {
   1286 		panic(3)
   1287 	}
   1288 	println() // ok
   1289 }
   1290 
   1291 var _ = func() int {
   1292 	print(1)
   1293 	if x == nil {
   1294 		panic(2)
   1295 	}
   1296 	println() // ok
   1297 }
   1298 
   1299 var _ = func() int {
   1300 L:
   1301 	print(1)
   1302 	if x == nil {
   1303 		panic(2)
   1304 	} else if x == 1 {
   1305 		return 0
   1306 	} else if x != 1 {
   1307 		panic(3)
   1308 	}
   1309 	println() // ok
   1310 }
   1311 
   1312 var _ = func() int {
   1313 	print(1)
   1314 	for {
   1315 	}
   1316 	println() // ERROR "unreachable code"
   1317 }
   1318 
   1319 var _ = func() int {
   1320 	for {
   1321 		for {
   1322 			break
   1323 		}
   1324 	}
   1325 	println() // ERROR "unreachable code"
   1326 }
   1327 
   1328 var _ = func() int {
   1329 	for {
   1330 		for {
   1331 			break
   1332 			println() // ERROR "unreachable code"
   1333 		}
   1334 	}
   1335 }
   1336 
   1337 var _ = func() int {
   1338 	for {
   1339 		for {
   1340 			continue
   1341 			println() // ERROR "unreachable code"
   1342 		}
   1343 	}
   1344 }
   1345 
   1346 var _ = func() int {
   1347 	for {
   1348 	L:
   1349 		for {
   1350 			break L
   1351 		}
   1352 	}
   1353 	println() // ERROR "unreachable code"
   1354 }
   1355 
   1356 var _ = func() int {
   1357 	print(1)
   1358 	for {
   1359 		break
   1360 	}
   1361 	println() // ok
   1362 }
   1363 
   1364 var _ = func() int {
   1365 	for {
   1366 		for {
   1367 		}
   1368 		break // ERROR "unreachable code"
   1369 	}
   1370 	println() // ok
   1371 }
   1372 
   1373 var _ = func() int {
   1374 L:
   1375 	for {
   1376 		for {
   1377 			break L
   1378 		}
   1379 	}
   1380 	println() // ok
   1381 }
   1382 
   1383 var _ = func() int {
   1384 	print(1)
   1385 	for x == nil {
   1386 	}
   1387 	println() // ok
   1388 }
   1389 
   1390 var _ = func() int {
   1391 	for x == nil {
   1392 		for {
   1393 			break
   1394 		}
   1395 	}
   1396 	println() // ok
   1397 }
   1398 
   1399 var _ = func() int {
   1400 	for x == nil {
   1401 	L:
   1402 		for {
   1403 			break L
   1404 		}
   1405 	}
   1406 	println() // ok
   1407 }
   1408 
   1409 var _ = func() int {
   1410 	print(1)
   1411 	for true {
   1412 	}
   1413 	println() // ok
   1414 }
   1415 
   1416 var _ = func() int {
   1417 	for true {
   1418 		for {
   1419 			break
   1420 		}
   1421 	}
   1422 	println() // ok
   1423 }
   1424 
   1425 var _ = func() int {
   1426 	for true {
   1427 	L:
   1428 		for {
   1429 			break L
   1430 		}
   1431 	}
   1432 	println() // ok
   1433 }
   1434 
   1435 var _ = func() int {
   1436 	print(1)
   1437 	select {}
   1438 	println() // ERROR "unreachable code"
   1439 }
   1440 
   1441 var _ = func() int {
   1442 	print(1)
   1443 	select {
   1444 	case <-c:
   1445 		print(2)
   1446 		panic("abc")
   1447 		println() // ERROR "unreachable code"
   1448 	}
   1449 }
   1450 
   1451 var _ = func() int {
   1452 	print(1)
   1453 	select {
   1454 	case <-c:
   1455 		print(2)
   1456 		panic("abc")
   1457 	}
   1458 	println() // ERROR "unreachable code"
   1459 }
   1460 
   1461 var _ = func() int {
   1462 	print(1)
   1463 	select {
   1464 	case <-c:
   1465 		print(2)
   1466 		for {
   1467 		}
   1468 		println() // ERROR "unreachable code"
   1469 	}
   1470 }
   1471 
   1472 var _ = func() int {
   1473 	print(1)
   1474 	select {
   1475 	case <-c:
   1476 		print(2)
   1477 		for {
   1478 		}
   1479 	}
   1480 	println() // ERROR "unreachable code"
   1481 }
   1482 
   1483 var _ = func() int {
   1484 L:
   1485 	print(1)
   1486 	select {
   1487 	case <-c:
   1488 		print(2)
   1489 		panic("abc")
   1490 		println() // ERROR "unreachable code"
   1491 	case c <- 1:
   1492 		print(2)
   1493 		goto L
   1494 		println() // ERROR "unreachable code"
   1495 	}
   1496 }
   1497 
   1498 var _ = func() int {
   1499 L:
   1500 	print(1)
   1501 	select {
   1502 	case <-c:
   1503 		print(2)
   1504 		panic("abc")
   1505 	case c <- 1:
   1506 		print(2)
   1507 		goto L
   1508 	}
   1509 	println() // ERROR "unreachable code"
   1510 }
   1511 
   1512 var _ = func() int {
   1513 	print(1)
   1514 	select {
   1515 	case <-c:
   1516 		print(2)
   1517 		panic("abc")
   1518 		println() // ERROR "unreachable code"
   1519 	default:
   1520 		select {}
   1521 		println() // ERROR "unreachable code"
   1522 	}
   1523 }
   1524 
   1525 var _ = func() int {
   1526 	print(1)
   1527 	select {
   1528 	case <-c:
   1529 		print(2)
   1530 		panic("abc")
   1531 	default:
   1532 		select {}
   1533 	}
   1534 	println() // ERROR "unreachable code"
   1535 }
   1536 
   1537 var _ = func() int {
   1538 	print(1)
   1539 	select {
   1540 	case <-c:
   1541 		print(2)
   1542 	}
   1543 	println() // ok
   1544 }
   1545 
   1546 var _ = func() int {
   1547 L:
   1548 	print(1)
   1549 	select {
   1550 	case <-c:
   1551 		print(2)
   1552 		panic("abc")
   1553 		goto L // ERROR "unreachable code"
   1554 	case c <- 1:
   1555 		print(2)
   1556 	}
   1557 	println() // ok
   1558 }
   1559 
   1560 var _ = func() int {
   1561 	print(1)
   1562 	select {
   1563 	case <-c:
   1564 		print(2)
   1565 		panic("abc")
   1566 	default:
   1567 		print(2)
   1568 	}
   1569 	println() // ok
   1570 }
   1571 
   1572 var _ = func() int {
   1573 	print(1)
   1574 	select {
   1575 	default:
   1576 		break
   1577 	}
   1578 	println() // ok
   1579 }
   1580 
   1581 var _ = func() int {
   1582 	print(1)
   1583 	select {
   1584 	case <-c:
   1585 		print(2)
   1586 		panic("abc")
   1587 		break // ERROR "unreachable code"
   1588 	}
   1589 	println() // ok
   1590 }
   1591 
   1592 var _ = func() int {
   1593 	print(1)
   1594 L:
   1595 	select {
   1596 	case <-c:
   1597 		print(2)
   1598 		for {
   1599 			break L
   1600 		}
   1601 	}
   1602 	println() // ok
   1603 }
   1604 
   1605 var _ = func() int {
   1606 	print(1)
   1607 L:
   1608 	select {
   1609 	case <-c:
   1610 		print(2)
   1611 		panic("abc")
   1612 	case c <- 1:
   1613 		print(2)
   1614 		break L
   1615 	}
   1616 	println() // ok
   1617 }
   1618 
   1619 var _ = func() int {
   1620 	print(1)
   1621 	select {
   1622 	case <-c:
   1623 		print(1)
   1624 		panic("abc")
   1625 	default:
   1626 		select {}
   1627 		break // ERROR "unreachable code"
   1628 	}
   1629 	println() // ok
   1630 }
   1631 
   1632 var _ = func() int {
   1633 	print(1)
   1634 	switch x {
   1635 	case 1:
   1636 		print(2)
   1637 		panic(3)
   1638 		println() // ERROR "unreachable code"
   1639 	default:
   1640 		return 4
   1641 		println() // ERROR "unreachable code"
   1642 	}
   1643 }
   1644 
   1645 var _ = func() int {
   1646 	print(1)
   1647 	switch x {
   1648 	case 1:
   1649 		print(2)
   1650 		panic(3)
   1651 	default:
   1652 		return 4
   1653 	}
   1654 	println() // ERROR "unreachable code"
   1655 }
   1656 
   1657 var _ = func() int {
   1658 	print(1)
   1659 	switch x {
   1660 	default:
   1661 		return 4
   1662 		println() // ERROR "unreachable code"
   1663 	case 1:
   1664 		print(2)
   1665 		panic(3)
   1666 		println() // ERROR "unreachable code"
   1667 	}
   1668 }
   1669 
   1670 var _ = func() int {
   1671 	print(1)
   1672 	switch x {
   1673 	default:
   1674 		return 4
   1675 	case 1:
   1676 		print(2)
   1677 		panic(3)
   1678 	}
   1679 	println() // ERROR "unreachable code"
   1680 }
   1681 
   1682 var _ = func() int {
   1683 	print(1)
   1684 	switch x {
   1685 	case 1:
   1686 		print(2)
   1687 		fallthrough
   1688 	default:
   1689 		return 4
   1690 		println() // ERROR "unreachable code"
   1691 	}
   1692 }
   1693 
   1694 var _ = func() int {
   1695 	print(1)
   1696 	switch x {
   1697 	case 1:
   1698 		print(2)
   1699 		fallthrough
   1700 	default:
   1701 		return 4
   1702 	}
   1703 	println() // ERROR "unreachable code"
   1704 }
   1705 
   1706 var _ = func() int {
   1707 	print(1)
   1708 	switch {
   1709 	}
   1710 	println() // ok
   1711 }
   1712 
   1713 var _ = func() int {
   1714 	print(1)
   1715 	switch x {
   1716 	case 1:
   1717 		print(2)
   1718 		panic(3)
   1719 	case 2:
   1720 		return 4
   1721 	}
   1722 	println() // ok
   1723 }
   1724 
   1725 var _ = func() int {
   1726 	print(1)
   1727 	switch x {
   1728 	case 2:
   1729 		return 4
   1730 	case 1:
   1731 		print(2)
   1732 		panic(3)
   1733 	}
   1734 	println() // ok
   1735 }
   1736 
   1737 var _ = func() int {
   1738 	print(1)
   1739 	switch x {
   1740 	case 1:
   1741 		print(2)
   1742 		fallthrough
   1743 	case 2:
   1744 		return 4
   1745 	}
   1746 	println() // ok
   1747 }
   1748 
   1749 var _ = func() int {
   1750 	print(1)
   1751 	switch x {
   1752 	case 1:
   1753 		print(2)
   1754 		panic(3)
   1755 	}
   1756 	println() // ok
   1757 }
   1758 
   1759 var _ = func() int {
   1760 	print(1)
   1761 L:
   1762 	switch x {
   1763 	case 1:
   1764 		print(2)
   1765 		panic(3)
   1766 		break L // ERROR "unreachable code"
   1767 	default:
   1768 		return 4
   1769 	}
   1770 	println() // ok
   1771 }
   1772 
   1773 var _ = func() int {
   1774 	print(1)
   1775 	switch x {
   1776 	default:
   1777 		return 4
   1778 		break // ERROR "unreachable code"
   1779 	case 1:
   1780 		print(2)
   1781 		panic(3)
   1782 	}
   1783 	println() // ok
   1784 }
   1785 
   1786 var _ = func() int {
   1787 	print(1)
   1788 L:
   1789 	switch x {
   1790 	case 1:
   1791 		print(2)
   1792 		for {
   1793 			break L
   1794 		}
   1795 	default:
   1796 		return 4
   1797 	}
   1798 	println() // ok
   1799 }
   1800 
   1801 var _ = func() int {
   1802 	print(1)
   1803 	switch x.(type) {
   1804 	case int:
   1805 		print(2)
   1806 		panic(3)
   1807 		println() // ERROR "unreachable code"
   1808 	default:
   1809 		return 4
   1810 		println() // ERROR "unreachable code"
   1811 	}
   1812 }
   1813 
   1814 var _ = func() int {
   1815 	print(1)
   1816 	switch x.(type) {
   1817 	case int:
   1818 		print(2)
   1819 		panic(3)
   1820 	default:
   1821 		return 4
   1822 	}
   1823 	println() // ERROR "unreachable code"
   1824 }
   1825 
   1826 var _ = func() int {
   1827 	print(1)
   1828 	switch x.(type) {
   1829 	default:
   1830 		return 4
   1831 		println() // ERROR "unreachable code"
   1832 	case int:
   1833 		print(2)
   1834 		panic(3)
   1835 		println() // ERROR "unreachable code"
   1836 	}
   1837 }
   1838 
   1839 var _ = func() int {
   1840 	print(1)
   1841 	switch x.(type) {
   1842 	default:
   1843 		return 4
   1844 	case int:
   1845 		print(2)
   1846 		panic(3)
   1847 	}
   1848 	println() // ERROR "unreachable code"
   1849 }
   1850 
   1851 var _ = func() int {
   1852 	print(1)
   1853 	switch x.(type) {
   1854 	case int:
   1855 		print(2)
   1856 		fallthrough
   1857 	default:
   1858 		return 4
   1859 		println() // ERROR "unreachable code"
   1860 	}
   1861 }
   1862 
   1863 var _ = func() int {
   1864 	print(1)
   1865 	switch x.(type) {
   1866 	case int:
   1867 		print(2)
   1868 		fallthrough
   1869 	default:
   1870 		return 4
   1871 	}
   1872 	println() // ERROR "unreachable code"
   1873 }
   1874 
   1875 var _ = func() int {
   1876 	print(1)
   1877 	switch {
   1878 	}
   1879 	println() // ok
   1880 }
   1881 
   1882 var _ = func() int {
   1883 	print(1)
   1884 	switch x.(type) {
   1885 	case int:
   1886 		print(2)
   1887 		panic(3)
   1888 	case float64:
   1889 		return 4
   1890 	}
   1891 	println() // ok
   1892 }
   1893 
   1894 var _ = func() int {
   1895 	print(1)
   1896 	switch x.(type) {
   1897 	case float64:
   1898 		return 4
   1899 	case int:
   1900 		print(2)
   1901 		panic(3)
   1902 	}
   1903 	println() // ok
   1904 }
   1905 
   1906 var _ = func() int {
   1907 	print(1)
   1908 	switch x.(type) {
   1909 	case int:
   1910 		print(2)
   1911 		fallthrough
   1912 	case float64:
   1913 		return 4
   1914 	}
   1915 	println() // ok
   1916 }
   1917 
   1918 var _ = func() int {
   1919 	print(1)
   1920 	switch x.(type) {
   1921 	case int:
   1922 		print(2)
   1923 		panic(3)
   1924 	}
   1925 	println() // ok
   1926 }
   1927 
   1928 var _ = func() int {
   1929 	print(1)
   1930 L:
   1931 	switch x.(type) {
   1932 	case int:
   1933 		print(2)
   1934 		panic(3)
   1935 		break L // ERROR "unreachable code"
   1936 	default:
   1937 		return 4
   1938 	}
   1939 	println() // ok
   1940 }
   1941 
   1942 var _ = func() int {
   1943 	print(1)
   1944 	switch x.(type) {
   1945 	default:
   1946 		return 4
   1947 		break // ERROR "unreachable code"
   1948 	case int:
   1949 		print(2)
   1950 		panic(3)
   1951 	}
   1952 	println() // ok
   1953 }
   1954 
   1955 var _ = func() int {
   1956 	print(1)
   1957 L:
   1958 	switch x.(type) {
   1959 	case int:
   1960 		print(2)
   1961 		for {
   1962 			break L
   1963 		}
   1964 	default:
   1965 		return 4
   1966 	}
   1967 	println() // ok
   1968 }
   1969 
   1970 // again, but without the leading print(1).
   1971 // testing that everything works when the terminating statement is first.
   1972 
   1973 var _ = func() int {
   1974 	println() // ok
   1975 }
   1976 
   1977 var _ = func() int {
   1978 	return 2
   1979 	println() // ERROR "unreachable code"
   1980 }
   1981 
   1982 var _ = func() int {
   1983 L:
   1984 	goto L
   1985 	println() // ERROR "unreachable code"
   1986 }
   1987 
   1988 var _ = func() int {
   1989 	panic(2)
   1990 	println() // ERROR "unreachable code"
   1991 }
   1992 
   1993 // but only builtin panic
   1994 var _ = func() int {
   1995 	var panic = func(int) {}
   1996 	panic(2)
   1997 	println() // ok
   1998 }
   1999 
   2000 var _ = func() int {
   2001 	{
   2002 		return 2
   2003 		println() // ERROR "unreachable code"
   2004 	}
   2005 }
   2006 
   2007 var _ = func() int {
   2008 	{
   2009 		return 2
   2010 	}
   2011 	println() // ERROR "unreachable code"
   2012 }
   2013 
   2014 var _ = func() int {
   2015 L:
   2016 	{
   2017 		goto L
   2018 		println() // ERROR "unreachable code"
   2019 	}
   2020 }
   2021 
   2022 var _ = func() int {
   2023 L:
   2024 	{
   2025 		goto L
   2026 	}
   2027 	println() // ERROR "unreachable code"
   2028 }
   2029 
   2030 var _ = func() int {
   2031 	{
   2032 		panic(2)
   2033 		println() // ERROR "unreachable code"
   2034 	}
   2035 }
   2036 
   2037 var _ = func() int {
   2038 	{
   2039 		panic(2)
   2040 	}
   2041 	println() // ERROR "unreachable code"
   2042 }
   2043 
   2044 var _ = func() int {
   2045 	return 2
   2046 	{ // ERROR "unreachable code"
   2047 	}
   2048 	println() // ok
   2049 }
   2050 
   2051 var _ = func() int {
   2052 L:
   2053 	goto L
   2054 	{ // ERROR "unreachable code"
   2055 	}
   2056 	println() // ok
   2057 }
   2058 
   2059 var _ = func() int {
   2060 	panic(2)
   2061 	{ // ERROR "unreachable code"
   2062 	}
   2063 	println() // ok
   2064 }
   2065 
   2066 var _ = func() int {
   2067 	{
   2068 		return 2
   2069 		{ // ERROR "unreachable code"
   2070 		}
   2071 	}
   2072 	println() // ok
   2073 }
   2074 
   2075 var _ = func() int {
   2076 L:
   2077 	{
   2078 		goto L
   2079 		{ // ERROR "unreachable code"
   2080 		}
   2081 	}
   2082 	println() // ok
   2083 }
   2084 
   2085 var _ = func() int {
   2086 	{
   2087 		panic(2)
   2088 		{ // ERROR "unreachable code"
   2089 		}
   2090 	}
   2091 	println() // ok
   2092 }
   2093 
   2094 var _ = func() int {
   2095 	{
   2096 		return 2
   2097 	}
   2098 	{ // ERROR "unreachable code"
   2099 	}
   2100 	println() // ok
   2101 }
   2102 
   2103 var _ = func() int {
   2104 L:
   2105 	{
   2106 		goto L
   2107 	}
   2108 	{ // ERROR "unreachable code"
   2109 	}
   2110 	println() // ok
   2111 }
   2112 
   2113 var _ = func() int {
   2114 	{
   2115 		panic(2)
   2116 	}
   2117 	{ // ERROR "unreachable code"
   2118 	}
   2119 	println() // ok
   2120 }
   2121 
   2122 var _ = func() {
   2123 	// goto without label used to panic
   2124 	goto
   2125 }
   2126