1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:04:42 -07:00

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:
Robert Griesemer 2013-10-07 20:27:21 -07:00
parent d5044c7ed2
commit 5d9b86d6ce
2 changed files with 26 additions and 6 deletions

View File

@ -511,18 +511,18 @@ func (check *checker) stmt(ctxt stmtContext, s ast.Stmt) {
switch typ := x.typ.Underlying().(type) {
case *Basic:
if isString(typ) {
key = Typ[UntypedInt]
val = Typ[UntypedRune]
key = Typ[Int]
val = Typ[Rune]
}
case *Array:
key = Typ[UntypedInt]
key = Typ[Int]
val = typ.elt
case *Slice:
key = Typ[UntypedInt]
key = Typ[Int]
val = typ.elt
case *Pointer:
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
key = Typ[UntypedInt]
key = Typ[Int]
val = typ.elt
}
case *Map:

View File

@ -507,7 +507,7 @@ func typeswitch2() {
}
}
func rangeloops() {
func rangeloops1() {
var (
x int
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() {
goto L0
goto L1