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:
parent
82b913fb17
commit
b31dcd1655
@ -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
|
||||
|
4
go/types/testdata/expr3.src
vendored
4
go/types/testdata/expr3.src
vendored
@ -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
|
||||
|
5
go/types/testdata/stmt0.src
vendored
5
go/types/testdata/stmt0.src
vendored
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user