go/types: comma-ok expressions return untyped boolean as 2nd result

Per acceptance of https://golang.org/cl/112320045/ .

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/113990043
This commit is contained in:
Robert Griesemer 2014-08-05 11:34:36 -07:00
parent 82b913fb17
commit b31dcd1655
3 changed files with 8 additions and 3 deletions

View File

@ -140,7 +140,7 @@ func unpack(get getter, n int, allowCommaOk bool) (getter, int, bool) {
if x0.mode == mapindex || x0.mode == commaok { if x0.mode == mapindex || x0.mode == commaok {
// comma-ok value // comma-ok value
if allowCommaOk { if allowCommaOk {
a := [2]Type{x0.typ, Typ[Bool]} a := [2]Type{x0.typ, Typ[UntypedBool]}
return func(x *operand, i int) { return func(x *operand, i int) {
x.mode = value x.mode = value
x.expr = x0.expr x.expr = x0.expr

View File

@ -98,7 +98,7 @@ func indexes() {
// ok is of type bool // ok is of type bool
type mybool bool type mybool bool
var ok mybool var ok mybool
_, ok = m /* ERROR "cannot assign" */ ["bar"] _, ok = m["bar"]
_ = ok _ = ok
@ -372,7 +372,7 @@ func type_asserts() {
// ok value is of type bool // ok value is of type bool
var myok mybool var myok mybool
_, myok = e /* ERROR "cannot assign" */ .(int) _, myok = e.(int)
_ = myok _ = myok
var t I var t I

View File

@ -95,14 +95,18 @@ func assignments1() {
} }
func assignments2() { func assignments2() {
type mybool bool
var m map[string][]bool var m map[string][]bool
var s []bool var s []bool
var b bool var b bool
var d mybool
_ = s _ = s
_ = b _ = b
_ = d
// assignments to map index expressions are ok // assignments to map index expressions are ok
s, b = m["foo"] s, b = m["foo"]
_, d = m["bar"]
m["foo"] = nil m["foo"] = nil
m["foo"] = nil /* ERROR assignment count mismatch */ , false m["foo"] = nil /* ERROR assignment count mismatch */ , false
_ = append(m["foo"]) _ = append(m["foo"])
@ -110,6 +114,7 @@ func assignments2() {
var c chan int var c chan int
_, b = <-c _, b = <-c
_, d = <-c
<- /* ERROR cannot assign */ c = 0 <- /* ERROR cannot assign */ c = 0
<-c = 0 /* ERROR assignment count mismatch */ , false <-c = 0 /* ERROR assignment count mismatch */ , false