Change iterate variable types from ptr to slice

This commit is contained in:
Nigel Tao committed 2018-05-04 13:20:34 +10:00
1 parent d85a94360e
commit 96a549814d
8 files changed
+54 -52

No files matched your search

+2 -4
View File
@@ -304,8 +304,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
q.facts = q.facts[:0]
for _, o := range n.Variables() {
v := o.Var()
// TODO: use the XType(), not the Value().MType().
q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.Value().MType(), n.Step()))
q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.XType(), n.Step()))
}
for _, o := range n.Body() {
if err := q.bcheckStatement(o); err != nil {
@@ -319,8 +318,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
q.facts = q.facts[:0]
for _, o := range n.Variables() {
v := o.Var()
// TODO: use the XType(), not the Value().MType().
q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.Value().MType(), t.ID1))
q.facts = append(q.facts, makeSliceLengthEqEq(v.Name(), v.XType(), t.ID1))
}
for _, o := range n.Tail() {
if err := q.bcheckStatement(o); err != nil {
+4 -8
View File
@@ -206,17 +206,13 @@ func (q *checker) tcheckStatement(n *a.Node) error {
lTyp := n.XType()
rTyp := value.MType()
if n.IterateVariable() {
if lTyp.Decorator() != t.IDPtr {
return fmt.Errorf("check: iterate variable %q, of type %q, does not have a pointer type",
if !lTyp.IsSliceType() {
return fmt.Errorf("check: iterate variable %q, of type %q, does not have a slice type",
n.Name().Str(q.tm), lTyp.Str(q.tm))
}
if !rTyp.IsSliceType() {
return fmt.Errorf("check: iterate range %q, of type %q, does not have a slice type",
value.Str(q.tm), rTyp.Str(q.tm))
}
if !lTyp.Inner().Eq(rTyp.Inner()) {
if !lTyp.Eq(rTyp) {
return fmt.Errorf("check: cannot iterate %q of type %q over %q of type %q "+
"as their inner types don't match",
"as their types don't match",
n.Name().Str(q.tm), lTyp.Str(q.tm), value.Str(q.tm), rTyp.Str(q.tm))
}
} else if err := q.tcheckEq(n.Name(), nil, lTyp, value, rTyp); err != nil {