]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: move Checker.indexedElts into literals.go where it belongs
authorRobert Griesemer <gri@golang.org>
Tue, 24 Sep 2024 21:08:28 +0000 (14:08 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 24 Sep 2024 23:20:50 +0000 (23:20 +0000)
The function is only used by Checker.compositeLit.
Also, now its go/types source can be gerated from the types2 source.
No other code changes.

Change-Id: I88b7ad371d809a5d9bf8e635d9e003ba0a71ab78
Reviewed-on: https://go-review.googlesource.com/c/go/+/615635
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

src/cmd/compile/internal/types2/index.go
src/cmd/compile/internal/types2/literals.go
src/go/types/index.go
src/go/types/literals.go

index 51684340f722b986b881b9f64f167f82c4d4c33e..d1d7a530b6e74384b98d1d72baa692a4989b306b 100644 (file)
@@ -415,50 +415,3 @@ func (check *Checker) isValidIndex(x *operand, code Code, what string, allowNega
 
        return true
 }
-
-// indexedElts checks the elements (elts) of an array or slice composite literal
-// against the literal's element type (typ), and the element indices against
-// the literal length if known (length >= 0). It returns the length of the
-// literal (maximum index value + 1).
-func (check *Checker) indexedElts(elts []syntax.Expr, typ Type, length int64) int64 {
-       visited := make(map[int64]bool, len(elts))
-       var index, max int64
-       for _, e := range elts {
-               // determine and check index
-               validIndex := false
-               eval := e
-               if kv, _ := e.(*syntax.KeyValueExpr); kv != nil {
-                       if typ, i := check.index(kv.Key, length); isValid(typ) {
-                               if i >= 0 {
-                                       index = i
-                                       validIndex = true
-                               } else {
-                                       check.errorf(e, InvalidLitIndex, "index %s must be integer constant", kv.Key)
-                               }
-                       }
-                       eval = kv.Value
-               } else if length >= 0 && index >= length {
-                       check.errorf(e, OversizeArrayLit, "index %d is out of bounds (>= %d)", index, length)
-               } else {
-                       validIndex = true
-               }
-
-               // if we have a valid index, check for duplicate entries
-               if validIndex {
-                       if visited[index] {
-                               check.errorf(e, DuplicateLitKey, "duplicate index %d in array or slice literal", index)
-                       }
-                       visited[index] = true
-               }
-               index++
-               if index > max {
-                       max = index
-               }
-
-               // check element against composite literal element type
-               var x operand
-               check.exprWithHint(&x, eval, typ)
-               check.assignment(&x, typ, "array or slice literal")
-       }
-       return max
-}
index 1a90700ade23ee87ee3006ccd118f72d570b218f..7e16d9d4c16bb90651e9c4283325b2589b63e092 100644 (file)
@@ -340,3 +340,50 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
        x.mode = value
        x.typ = typ
 }
+
+// indexedElts checks the elements (elts) of an array or slice composite literal
+// against the literal's element type (typ), and the element indices against
+// the literal length if known (length >= 0). It returns the length of the
+// literal (maximum index value + 1).
+func (check *Checker) indexedElts(elts []syntax.Expr, typ Type, length int64) int64 {
+       visited := make(map[int64]bool, len(elts))
+       var index, max int64
+       for _, e := range elts {
+               // determine and check index
+               validIndex := false
+               eval := e
+               if kv, _ := e.(*syntax.KeyValueExpr); kv != nil {
+                       if typ, i := check.index(kv.Key, length); isValid(typ) {
+                               if i >= 0 {
+                                       index = i
+                                       validIndex = true
+                               } else {
+                                       check.errorf(e, InvalidLitIndex, "index %s must be integer constant", kv.Key)
+                               }
+                       }
+                       eval = kv.Value
+               } else if length >= 0 && index >= length {
+                       check.errorf(e, OversizeArrayLit, "index %d is out of bounds (>= %d)", index, length)
+               } else {
+                       validIndex = true
+               }
+
+               // if we have a valid index, check for duplicate entries
+               if validIndex {
+                       if visited[index] {
+                               check.errorf(e, DuplicateLitKey, "duplicate index %d in array or slice literal", index)
+                       }
+                       visited[index] = true
+               }
+               index++
+               if index > max {
+                       max = index
+               }
+
+               // check element against composite literal element type
+               var x operand
+               check.exprWithHint(&x, eval, typ)
+               check.assignment(&x, typ, "array or slice literal")
+       }
+       return max
+}
index 1b1a7b0007ab8781eef8485da90775322feb2d73..e52d9a00ff2adfd6e15cf61e75b3b44c808a142d 100644 (file)
@@ -408,50 +408,3 @@ func (check *Checker) isValidIndex(x *operand, code Code, what string, allowNega
 
        return true
 }
-
-// indexedElts checks the elements (elts) of an array or slice composite literal
-// against the literal's element type (typ), and the element indices against
-// the literal length if known (length >= 0). It returns the length of the
-// literal (maximum index value + 1).
-func (check *Checker) indexedElts(elts []ast.Expr, typ Type, length int64) int64 {
-       visited := make(map[int64]bool, len(elts))
-       var index, max int64
-       for _, e := range elts {
-               // determine and check index
-               validIndex := false
-               eval := e
-               if kv, _ := e.(*ast.KeyValueExpr); kv != nil {
-                       if typ, i := check.index(kv.Key, length); isValid(typ) {
-                               if i >= 0 {
-                                       index = i
-                                       validIndex = true
-                               } else {
-                                       check.errorf(e, InvalidLitIndex, "index %s must be integer constant", kv.Key)
-                               }
-                       }
-                       eval = kv.Value
-               } else if length >= 0 && index >= length {
-                       check.errorf(e, OversizeArrayLit, "index %d is out of bounds (>= %d)", index, length)
-               } else {
-                       validIndex = true
-               }
-
-               // if we have a valid index, check for duplicate entries
-               if validIndex {
-                       if visited[index] {
-                               check.errorf(e, DuplicateLitKey, "duplicate index %d in array or slice literal", index)
-                       }
-                       visited[index] = true
-               }
-               index++
-               if index > max {
-                       max = index
-               }
-
-               // check element against composite literal element type
-               var x operand
-               check.exprWithHint(&x, eval, typ)
-               check.assignment(&x, typ, "array or slice literal")
-       }
-       return max
-}
index efcaa859dccd095426f64766b816a63ace340bee..46a93bb10a0a52f468cb8f000536da0d750f8151 100644 (file)
@@ -344,3 +344,50 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
        x.mode = value
        x.typ = typ
 }
+
+// indexedElts checks the elements (elts) of an array or slice composite literal
+// against the literal's element type (typ), and the element indices against
+// the literal length if known (length >= 0). It returns the length of the
+// literal (maximum index value + 1).
+func (check *Checker) indexedElts(elts []ast.Expr, typ Type, length int64) int64 {
+       visited := make(map[int64]bool, len(elts))
+       var index, max int64
+       for _, e := range elts {
+               // determine and check index
+               validIndex := false
+               eval := e
+               if kv, _ := e.(*ast.KeyValueExpr); kv != nil {
+                       if typ, i := check.index(kv.Key, length); isValid(typ) {
+                               if i >= 0 {
+                                       index = i
+                                       validIndex = true
+                               } else {
+                                       check.errorf(e, InvalidLitIndex, "index %s must be integer constant", kv.Key)
+                               }
+                       }
+                       eval = kv.Value
+               } else if length >= 0 && index >= length {
+                       check.errorf(e, OversizeArrayLit, "index %d is out of bounds (>= %d)", index, length)
+               } else {
+                       validIndex = true
+               }
+
+               // if we have a valid index, check for duplicate entries
+               if validIndex {
+                       if visited[index] {
+                               check.errorf(e, DuplicateLitKey, "duplicate index %d in array or slice literal", index)
+                       }
+                       visited[index] = true
+               }
+               index++
+               if index > max {
+                       max = index
+               }
+
+               // check element against composite literal element type
+               var x operand
+               check.exprWithHint(&x, eval, typ)
+               check.assignment(&x, typ, "array or slice literal")
+       }
+       return max
+}