spec: document existing expression switch restrictions
spec: document existing expression switch restrictions

The spec didn't specify several aspects of expression switches:

- The switch expression is evaluated exactly once.

- Switch expressions evaluating to an untyped value are converted
  to the respective default type before use.

- An (untyped) nil value is not permitted as expression switch
  value. (We could permit it relatively easily, but gc doesn't,
  and disallowing it is in symmetry with the rules for var decls
  without explicit type and untyped initializer expressions.)

- The comparison x == t between each case expression x and
  switch expression value t must be valid.

- (Some) duplicate constant case expressions are not permitted.

This change also clarifies the following issues:

 4524: mult. equal int const switch case values should be illegal
                                         -> spec issue fixed
 6398: switch w/ no value uses bool rather than untyped bool
                                         -> spec issue fixed
11578: allows duplicate switch cases     -> go/types bug
11667: int overflow in switch expression -> go/types bug
11668: use of untyped nil in switch      -> not a gc bug

Fixes #4524.
Fixes #6398.
Fixes #11668.

Change-Id: Iae4ab3e714575a5d11c92c9b8fbf027aa706b370
Reviewed-on: https://go-review.googlesource.com/12711
Reviewed-by: Russ Cox <5ad239cb8a44f659eaaee0aa1ea5b94947abe557@golang.org>
Reviewed-by: Rob Pike <4dc7c9ec434ed06502767136789763ec11d2c4b7@golang.org>

snowsnail/go,zouchao2010/go,fjballest/golang,stormltf/go,andrewchambers/go,skotti/go,rachtsingh/gogojuice,sinuos/go,ganboing/go-esx,ErikDubbelboer/go,WIZARD-CXY/go,4ad/go,theif519/go,jasonxiong/go,xiuzhifu/go,alash3al/go,cainiaocome/go,kakuhiroshi/go,xujianhai/go,xujianhai/go,myPublicGit/go,danielsoro/go,Samurais/go,WIZARD-CXY/go,vsekhar/elastic-go,g522342435/go,youprofit/go,mwhudson/go,Young55555/go,mikekap/go,undergrowthlinear/go,albertjin/golang-go,ObjectiveJoe/go,jameskumar/go,jdhenke/go,roth1002/go,kakuhiroshi/go,rachtsingh/gogojuice,likesea/go,jacobhaven/go,JioCloud/go,mgyenik/go,nawawi/go,slavau/go,vsekhar/elastic-go,shines77/go,myPublicGit/go,theass/go,Cofyc/go,skatsuta/go,constantine001/go,sosop/go,vishsingh/go,miolini/go,parkdy/go,zcwfeng/go,joshsammut/go,Endika/go,vishsingh/go,kevinc0825/go,andrewchambers/go,jacobsa/go,ErikDubbelboer/go,zhangg/go,jdeng/go,rentongzhang/go,springning/go,jdhenke/go,Stan-Lin-/go,cloudflare/go,gdey/go,linux-on-ibm-z/go,zouchao2010/go,jmptrader/go,xujianhai/go,honsiorovskyi/go,4ad/go,sosop/go,danycoro/go,snowsnail/go,myPublicGit/go,malvira/go,snowsnail/go,CarterTsai/go,uileyar/go,yuhengye/go,Badredapple/go,josharian/go,NunoEdgarGub1/go,likesea/go,goodlang/good,likesea/go,g522342435/go,honsiorovskyi/go,g522342435/go,roth1002/go,CAFxX/go,slavau/go,Charlesdong/go-1,uileyar/go,momchil-velikov/go,cyberroadie/go,yuhengye/go,jdeng/go,CodyGuo/go,xujianhai/go,alex-zhang/go,kevinc0825/go,ichu501/go,cloudflare/go,NichoZhang/go,stormltf/go,NunoEdgarGub1/go,WIZARD-CXY/go,CodyGuo/go,Pulgafree/go,XuYunnan/go,theass/go,sndnvaps/go,b54898533/go,vsdutka/go,baiyunping333/go,NichoZhang/go,malvira/go,jameskumar/go,snowsnail/go,Endika/go,CodyGuo/go,zouchao2010/go,ichu501/go,cyberroadie/go,jacobhaven/go,ifagnosticism/go,Cofyc/go,derekmarcotte/go,alash3al/go,CiscoCloud/go,gdey/go,josharian/go,joshsammut/go,Cofyc/go,kakuhiroshi/go,baiyunping333/go,vsdutka/go,jefby/go,nakedgc/go,WIZARD-CXY/go,roth1002/go,linux-on-ibm-z/go,Charlesdong/go-1,jacobxk/go,josharian/go,deft-code/go,myPublicGit/go,donnel6809/go,WIZARD-CXY/go,danycoro/go,xujianhai/go,cookerzhu/go,CAFxX/go,Badredapple/go,yasarkunduz/go,ImJasonH/go,miolini/go,mdp/go,kakuhiroshi/go,myPublicGit/go,derekmarcotte/go,Pulgafree/go,wangfakang/go-1,mdp/go,suncycheng/go,ericsnowcurrently/go,donnel6809/go,akutz/go,JioCloud/go,willjunspecial/go,4ad/go,skatsuta/go,theif519/go,dafyddcrosby/go,mikekap/go,b54898533/go,zhangg/go,Jordanzuo/go,wangfakang/go-1,Young55555/go,miolini/go,deft-code/go,cookerzhu/go,snowsnail/go,arschles/go-1,springning/go,alash3al/go,ImJasonH/go,cainiaocome/go,willjunspecial/go,Samurais/go,ObjectiveJoe/go,ganboing/go-esx,skotti/go,alex-zhang/go,devpadawan/go,jonasi/go,ImJasonH/go,likesea/go,jonathanmarvens/go,constantine001/go,golang/go,skatsuta/go,famorted/go,yangzhongj/go,b54898533/go,yangzhongj/go,Endika/go,malvira/go,Samurais/go,kim-racktop/go,skotti/go,b54898533/go,snowsnail/go,leeric92/go,Young55555/go,fjballest/golang,xujianhai/go,joshsammut/go,cookerzhu/go,binarycrusader/go,polyverse-security/go,leeric92/go,donnel6809/go,jmptrader/go,jefby/go,undergrowthlinear/go,theif519/go,zouchao2010/go,shines77/go,malvira/go,GeorgiCodes/go,jacobhaven/go,jmptrader/go,dafyddcrosby/go,vsekhar/elastic-go,codestation/go,CodyGuo/go,theif519/go,leeric92/go,jonahglover/go,kakuhiroshi/go,jonathanmarvens/go,jmptrader/go,jonahglover/go,ichu501/go,jasonxiong/go,roth1002/go,yuhengye/go,cookerzhu/go,nakedgc/go,AALEKH/go,shines77/go,kakuhiroshi/go,famorted/go,golang/go,CiscoCloud/go,skatsuta/go,youprofit/go,xiaobodu/go,jacobsa/go,ifagnosticism/go,ImJasonH/go,AALEKH/go,suncycheng/go,dterei/go,jonasi/go,linux-on-ibm-z/go,jacobsa/go,mgyenik/go,alex-zhang/go,honsiorovskyi/go,suncycheng/go,polyverse-security/go,gdey/go,mdp/go,leeric92/go,nakedgc/go,vsdutka/go,sndnvaps/go,suncycheng/go,shines77/go,jacobxk/go,dafyddcrosby/go,xiuzhifu/go,jdeng/go,parkdy/go,yangzhongj/go,Jordanzuo/go,constantine001/go,ericsnowcurrently/go,cyberroadie/go,cainiaocome/go,shines77/go,mikekap/go,cookerzhu/go,cainiaocome/go,yuhengye/go,jacobsa/go,golang/go,wangfakang/go-1,slavau/go,arschles/go-1,xiaobodu/go,likesea/go,lihuanghai/go,danycoro/go,josharian/go,danielsoro/go,vishsingh/go,jasonxiong/go,nawawi/go,vsekhar/elastic-go,ObjectiveJoe/go,Endika/go,mikekap/go,goodlang/good,goodlang/good,theif519/go,parkdy/go,Badredapple/go,jacobhaven/go,Badredapple/go,dterei/go,kim-racktop/go,nakedgc/go,sosop/go,albertjin/golang-go,CarterTsai/go,beealone/go,mikekap/go,CAFxX/go,theass/go,danielsoro/go,AALEKH/go,devpadawan/go,Samurais/go,parkdy/go,qskycolor/go,yasarkunduz/go,deft-code/go,lihuanghai/go,sndnvaps/go,goodlang/good,jonasi/go,Young55555/go,jonathanmarvens/go,fjballest/golang,derekmarcotte/go,xiaobodu/go,stormltf/go,fjballest/golang,XuYunnan/go,ObjectiveJoe/go,shines77/go,g522342435/go,skotti/go,beealone/go,kim-racktop/go,Stan-Lin-/go,greyhwndz/go,linux-on-ibm-z/go,gdey/go,jdeng/go,zhangg/go,goodlang/good,jefby/go,vanloswang/go,Pulgafree/go,ichu501/go,donnel6809/go,rachtsingh/gogojuice,vsekhar/elastic-go,ErikDubbelboer/go,momchil-velikov/go,wangfakang/go-1,ObjectiveJoe/go,akutz/go,CodyGuo/go,wangfakang/go-1,mbrukman/go,jmptrader/go,ganboing/go-esx,chinanjjohn2012/go,dterei/go,g522342435/go,zcwfeng/go,willjunspecial/go,famorted/go,undergrowthlinear/go,Cofyc/go,andrewchambers/go,Badredapple/go,qskycolor/go,xiuzhifu/go,zouchao2010/go,Pulgafree/go,Endika/go,mwhudson/go,CarterTsai/go,cainiaocome/go,jonahglover/go,ImJasonH/go,jmptrader/go,sosop/go,jasonxiong/go,akutz/go,baiyunping333/go,ganboing/go-esx,Charlesdong/go-1,josharian/go,jdhenke/go,zhangg/go,AALEKH/go,GeorgiCodes/go,momchil-velikov/go,binarycrusader/go,mwhudson/go,zcwfeng/go,beealone/go,Stan-Lin-/go,kakuhiroshi/go,g522342435/go,codestation/go,jacobxk/go,andrewchambers/go,nawawi/go,wangfakang/go-1,4ad/go,samanalysis/go,honsiorovskyi/go,xiuzhifu/go,chinanjjohn2012/go,miolini/go,arschles/golang-go,ganboing/go-esx,parkdy/go,codestation/go,cloudflare/go,springning/go,CiscoCloud/go,nawawi/go,constantine001/go,roth1002/go,b54898533/go,chinanjjohn2012/go,rentongzhang/go,jdhenke/go,jonasi/go,sinuos/go,chinanjjohn2012/go,Jordanzuo/go,Pulgafree/go,constantine001/go,nawawi/go,CodyGuo/go,XuYunnan/go,GeorgiCodes/go,zhangg/go,albertjin/golang-go,jasonxiong/go,skatsuta/go,chinanjjohn2012/go,mgyenik/go,jdhenke/go,devpadawan/go,arschles/go-1,stormltf/go,ericsnowcurrently/go,xiuzhifu/go,qskycolor/go,cookerzhu/go,youprofit/go,mbrukman/go,miolini/go,undergrowthlinear/go,myPublicGit/go,yangzhongj/go,dafyddcrosby/go,linux-on-ibm-z/go,alash3al/go,cloudflare/go,stormltf/go,slavau/go,rentongzhang/go,xiaobodu/go,malvira/go,momchil-velikov/go,jonahglover/go,goodlang/good,jameskumar/go,4ad/go,mgyenik/go,AALEKH/go,jonahglover/go,CAFxX/go,kevinc0825/go,zcwfeng/go,ImJasonH/go,xiaobodu/go,cloudflare/go,honsiorovskyi/go,undergrowthlinear/go,qskycolor/go,greyhwndz/go,jefby/go,ifagnosticism/go,NichoZhang/go,albertjin/golang-go,xiaobodu/go,ErikDubbelboer/go,binarycrusader/go,christopher-henderson/Go,kevinc0825/go,beealone/go,cloudflare/go,mwhudson/go,binarycrusader/go,akutz/go,jasonxiong/go,WIZARD-CXY/go,sinuos/go,josharian/go,CAFxX/go,undergrowthlinear/go,uileyar/go,beealone/go,willjunspecial/go,yasarkunduz/go,jacobxk/go,samanalysis/go,andrewchambers/go,codestation/go,ganboing/go-esx,myPublicGit/go,odeke-em/go,dterei/go,XuYunnan/go,jdeng/go,famorted/go,nakedgc/go,codestation/go,baiyunping333/go,jonahglover/go,leeric92/go,odeke-em/go,NunoEdgarGub1/go,albertjin/golang-go,jonahglover/go,Stan-Lin-/go,NunoEdgarGub1/go,CarterTsai/go,gdey/go,willjunspecial/go,albertjin/golang-go,suncycheng/go,stormltf/go,greyhwndz/go,XuYunnan/go,leeric92/go,donnel6809/go,mwhudson/go,kevinc0825/go,monetate/go,arschles/go-1,jefby/go,wangfakang/go-1,NichoZhang/go,jonasi/go,jdhenke/go,xiuzhifu/go,sndnvaps/go,vsdutka/go,goodlang/good,rentongzhang/go,arschles/golang-go,myPublicGit/go,skotti/go,Cofyc/go,dpatel06/go,nakedgc/go,vishsingh/go,devpadawan/go,jdhenke/go,AALEKH/go,snowsnail/go,honsiorovskyi/go,odeke-em/go,joshsammut/go,Jordanzuo/go,polyverse-security/go,arschles/golang-go,suncycheng/go,jonathanmarvens/go,JioCloud/go,CarterTsai/go,roth1002/go,AALEKH/go,fjballest/golang,fjballest/golang,linux-on-ibm-z/go,jameskumar/go,vanloswang/go,vishsingh/go,mdp/go,theass/go,alex-zhang/go,jonathanmarvens/go,parkdy/go,4ad/go,baiyunping333/go,dafyddcrosby/go,g522342435/go,albertjin/golang-go,ericsnowcurrently/go,ObjectiveJoe/go,vishsingh/go,WIZARD-CXY/go,goodlang/good,mgyenik/go,zcwfeng/go,codestation/go,Jordanzuo/go,CarterTsai/go,NunoEdgarGub1/go,chinanjjohn2012/go,vsdutka/go,derekmarcotte/go,CarterTsai/go,yangzhongj/go,fjballest/golang,danycoro/go,gdey/go,jonathanmarvens/go,arschles/golang-go,andrewchambers/go,miolini/go,arschles/go-1,Charlesdong/go-1,cainiaocome/go,arschles/golang-go,Jordanzuo/go,chinanjjohn2012/go,ichu501/go,Stan-Lin-/go,skatsuta/go,zouchao2010/go,mdp/go,ericsnowcurrently/go,dpatel06/go,likesea/go,linux-on-ibm-z/go,odeke-em/go,ImJasonH/go,cyberroadie/go,binarycrusader/go,mbrukman/go,qskycolor/go,miolini/go,springning/go,constantine001/go,samanalysis/go,theass/go,GeorgiCodes/go,dpatel06/go,JioCloud/go,dpatel06/go,akutz/go,mgyenik/go,jefby/go,Stan-Lin-/go,b54898533/go,jonahglover/go,polyverse-security/go,Young55555/go,shines77/go,baiyunping333/go,snowsnail/go,dterei/go,donnel6809/go,famorted/go,qskycolor/go,kevinc0825/go,xujianhai/go,mgyenik/go,g522342435/go,xiuzhifu/go,NichoZhang/go,malvira/go,parkdy/go,mgyenik/go,derekmarcotte/go,cainiaocome/go,sndnvaps/go,yangzhongj/go,deft-code/go,danielsoro/go,sndnvaps/go,jacobhaven/go,jasonxiong/go,Samurais/go,vsdutka/go,golang/go,springning/go,rachtsingh/gogojuice,slavau/go,shines77/go,golang/go,ErikDubbelboer/go,alex-zhang/go,JioCloud/go,derekmarcotte/go,arschles/go-1,monetate/go,monetate/go,andrewchambers/go,mikekap/go,Endika/go,Charlesdong/go-1,ImJasonH/go,sndnvaps/go,cainiaocome/go,theif519/go,jacobsa/go,dpatel06/go,xujianhai/go,wangfakang/go-1,Badredapple/go,rentongzhang/go,GeorgiCodes/go,NunoEdgarGub1/go,ErikDubbelboer/go,vanloswang/go,ericsnowcurrently/go,alex-zhang/go,mwhudson/go,springning/go,danielsoro/go,donnel6809/go,deft-code/go,nakedgc/go,samanalysis/go,gdey/go,mbrukman/go,jacobxk/go,Charlesdong/go-1,mdp/go,Cofyc/go,alash3al/go,CAFxX/go,yuhengye/go,ganboing/go-esx,vsekhar/elastic-go,jameskumar/go,alex-zhang/go,Samurais/go,monetate/go,xiaobodu/go,dterei/go,cyberroadie/go,monetate/go,AALEKH/go,zouchao2010/go,CiscoCloud/go,ifagnosticism/go,yuhengye/go,mdp/go,CAFxX/go,Pulgafree/go,suncycheng/go,mbrukman/go,Endika/go,yuhengye/go,baiyunping333/go,arschles/golang-go,devpadawan/go,vanloswang/go,theif519/go,danielsoro/go,akutz/go,honsiorovskyi/go,arschles/golang-go,malvira/go,Jordanzuo/go,monetate/go,greyhwndz/go,arschles/go-1,jmptrader/go,nawawi/go,yangzhongj/go,jonathanmarvens/go,ichu501/go,vsekhar/elastic-go,golang/go,sosop/go,binarycrusader/go,youprofit/go,donnel6809/go,devpadawan/go,ericsnowcurrently/go,xiaobodu/go,joshsammut/go,jacobhaven/go,odeke-em/go,lihuanghai/go,youprofit/go,beealone/go,Charlesdong/go-1,zouchao2010/go,Endika/go,uileyar/go,momchil-velikov/go,WIZARD-CXY/go,dpatel06/go,sosop/go,lihuanghai/go,constantine001/go,zcwfeng/go,Samurais/go,kim-racktop/go,andrewchambers/go,binarycrusader/go,cyberroadie/go,yasarkunduz/go,jdeng/go,youprofit/go,yasarkunduz/go,undergrowthlinear/go,NichoZhang/go,kakuhiroshi/go,youprofit/go,kim-racktop/go,CiscoCloud/go,rachtsingh/gogojuice,monetate/go,momchil-velikov/go,kevinc0825/go,CAFxX/go,slavau/go,danycoro/go,binarycrusader/go,GeorgiCodes/go,Young55555/go,leeric92/go,deft-code/go,miolini/go,ichu501/go,beealone/go,sosop/go,codestation/go,ObjectiveJoe/go,mbrukman/go,danycoro/go,willjunspecial/go,jonasi/go,XuYunnan/go,golang/go,ganboing/go-esx,deft-code/go,jameskumar/go,fjballest/golang,danielsoro/go,devpadawan/go,honsiorovskyi/go,lihuanghai/go,malvira/go,dterei/go,dpatel06/go,ichu501/go,beealone/go,jacobsa/go,linux-on-ibm-z/go,theass/go,chinanjjohn2012/go,monetate/go,kim-racktop/go,CiscoCloud/go,danycoro/go,alash3al/go,joshsammut/go,mikekap/go,skotti/go,b54898533/go,sinuos/go,ifagnosticism/go,ifagnosticism/go,vishsingh/go,cookerzhu/go,jacobsa/go,stormltf/go,zcwfeng/go,slavau/go,jdhenke/go,mwhudson/go,dterei/go,momchil-velikov/go,likesea/go,jameskumar/go,akutz/go,polyverse-security/go,jonasi/go,4ad/go,yuhengye/go,kevinc0825/go,danycoro/go,cyberroadie/go,Young55555/go,greyhwndz/go,vanloswang/go,jefby/go,qskycolor/go,arschles/go-1,CarterTsai/go,derekmarcotte/go,XuYunnan/go,mikekap/go,rentongzhang/go,samanalysis/go,famorted/go,Badredapple/go,uileyar/go,roth1002/go,NichoZhang/go,ErikDubbelboer/go,samanalysis/go,theass/go,jacobxk/go,joshsammut/go,leeric92/go,kim-racktop/go,lihuanghai/go,GeorgiCodes/go,vanloswang/go,famorted/go,jameskumar/go,JioCloud/go,zhangg/go,cyberroadie/go,deft-code/go,golang/go,constantine001/go,ErikDubbelboer/go,skatsuta/go,mbrukman/go,zcwfeng/go,jdeng/go,rachtsingh/gogojuice,dafyddcrosby/go,greyhwndz/go,sinuos/go,jonasi/go,joshsammut/go,Charlesdong/go-1,CodyGuo/go,jmptrader/go,rentongzhang/go,springning/go,youprofit/go,skotti/go,zhangg/go,jdeng/go,dafyddcrosby/go,alash3al/go,uileyar/go,nawawi/go,sndnvaps/go,Young55555/go,Cofyc/go,yasarkunduz/go,NunoEdgarGub1/go,skotti/go,yasarkunduz/go,Pulgafree/go,undergrowthlinear/go,rentongzhang/go,rachtsingh/gogojuice,ObjectiveJoe/go,suncycheng/go,CodyGuo/go,arschles/golang-go,NichoZhang/go,GeorgiCodes/go,uileyar/go,gdey/go,xiuzhifu/go,Samurais/go,momchil-velikov/go,derekmarcotte/go,akutz/go,cloudflare/go,CiscoCloud/go,nawawi/go,jacobxk/go,odeke-em/go,dpatel06/go,danielsoro/go,nakedgc/go,alash3al/go,stormltf/go,vsdutka/go,Stan-Lin-/go,lihuanghai/go,odeke-em/go,polyverse-security/go,qskycolor/go,devpadawan/go,Badredapple/go,uileyar/go,yangzhongj/go,alex-zhang/go,samanalysis/go,slavau/go,ifagnosticism/go,Cofyc/go,springning/go,baiyunping333/go,sosop/go,polyverse-security/go,willjunspecial/go,skatsuta/go,Jordanzuo/go,zhangg/go,vanloswang/go,jefby/go,4ad/go,codestation/go,odeke-em/go,dafyddcrosby/go,mwhudson/go,ericsnowcurrently/go,josharian/go,jacobhaven/go,sinuos/go,b54898533/go,Pulgafree/go,willjunspecial/go,Stan-Lin-/go,likesea/go,jacobxk/go,albertjin/golang-go,JioCloud/go,josharian/go,JioCloud/go,samanalysis/go,roth1002/go,theass/go,vishsingh/go,vanloswang/go,vsdutka/go,kim-racktop/go,polyverse-security/go,cloudflare/go,XuYunnan/go,jacobhaven/go,parkdy/go,jasonxiong/go,mdp/go,mbrukman/go,lihuanghai/go,CiscoCloud/go,vsekhar/elastic-go,famorted/go,greyhwndz/go,greyhwndz/go,cookerzhu/go,rachtsingh/gogojuice,theif519/go,sinuos/go,yasarkunduz/go,jacobsa/go,jonathanmarvens/go,sinuos/go,NunoEdgarGub1/go,ifagnosticism/go