1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:14:46 -07:00

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 {
// comma-ok value
if allowCommaOk {
a := [2]Type{x0.typ, Typ[Bool]}
a := [2]Type{x0.typ, Typ[UntypedBool]}
return func(x *operand, i int) {
x.mode = value
x.expr = x0.expr

View File

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

View File

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