go.tools/go/types: range iteration variables are typed (not untyped)
R=adonovan CC=golang-dev https://golang.org/cl/14516044
This commit is contained in:
parent
d5044c7ed2
commit
5d9b86d6ce
|
@ -511,18 +511,18 @@ func (check *checker) stmt(ctxt stmtContext, s ast.Stmt) {
|
||||||
switch typ := x.typ.Underlying().(type) {
|
switch typ := x.typ.Underlying().(type) {
|
||||||
case *Basic:
|
case *Basic:
|
||||||
if isString(typ) {
|
if isString(typ) {
|
||||||
key = Typ[UntypedInt]
|
key = Typ[Int]
|
||||||
val = Typ[UntypedRune]
|
val = Typ[Rune]
|
||||||
}
|
}
|
||||||
case *Array:
|
case *Array:
|
||||||
key = Typ[UntypedInt]
|
key = Typ[Int]
|
||||||
val = typ.elt
|
val = typ.elt
|
||||||
case *Slice:
|
case *Slice:
|
||||||
key = Typ[UntypedInt]
|
key = Typ[Int]
|
||||||
val = typ.elt
|
val = typ.elt
|
||||||
case *Pointer:
|
case *Pointer:
|
||||||
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
|
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
|
||||||
key = Typ[UntypedInt]
|
key = Typ[Int]
|
||||||
val = typ.elt
|
val = typ.elt
|
||||||
}
|
}
|
||||||
case *Map:
|
case *Map:
|
||||||
|
|
|
@ -507,7 +507,7 @@ func typeswitch2() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func rangeloops() {
|
func rangeloops1() {
|
||||||
var (
|
var (
|
||||||
x int
|
x int
|
||||||
a [10]float32
|
a [10]float32
|
||||||
|
@ -612,6 +612,26 @@ func rangeloops() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func rangeloops2() {
|
||||||
|
type I int
|
||||||
|
type R rune
|
||||||
|
|
||||||
|
var a [10]int
|
||||||
|
var i I
|
||||||
|
_ = i
|
||||||
|
for i /* ERROR cannot assign */ = range a {}
|
||||||
|
for i /* ERROR cannot assign */ = range &a {}
|
||||||
|
for i /* ERROR cannot assign */ = range a[:] {}
|
||||||
|
|
||||||
|
var s string
|
||||||
|
var r R
|
||||||
|
_ = r
|
||||||
|
for i /* ERROR cannot assign */ = range s {}
|
||||||
|
for i /* ERROR cannot assign */ = range "foo" {}
|
||||||
|
for _, r /* ERROR cannot assign */ = range s {}
|
||||||
|
for _, r /* ERROR cannot assign */ = range "foo" {}
|
||||||
|
}
|
||||||
|
|
||||||
func labels0() {
|
func labels0() {
|
||||||
goto L0
|
goto L0
|
||||||
goto L1
|
goto L1
|
||||||
|
|
Loading…
Reference in New Issue