mirror of
https://github.com/golang/go
synced 2024-11-19 00:54:42 -07:00
go.tools/go/types: consistently use 'elem' instead of 'elt'
This is simply a rename of unexported struct fields. No other changes. R=adonovan CC=golang-dev https://golang.org/cl/17330043
This commit is contained in:
parent
cf08eefe7f
commit
1e05a58b11
@ -69,7 +69,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
|
|||||||
S := x.typ
|
S := x.typ
|
||||||
var T Type
|
var T Type
|
||||||
if s, _ := S.Underlying().(*Slice); s != nil {
|
if s, _ := S.Underlying().(*Slice); s != nil {
|
||||||
T = s.elt
|
T = s.elem
|
||||||
} else {
|
} else {
|
||||||
check.invalidArg(x.pos(), "%s is not a slice", x)
|
check.invalidArg(x.pos(), "%s is not a slice", x)
|
||||||
return
|
return
|
||||||
@ -262,7 +262,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
|
|||||||
// copy(x, y []T) int
|
// copy(x, y []T) int
|
||||||
var dst Type
|
var dst Type
|
||||||
if t, _ := x.typ.Underlying().(*Slice); t != nil {
|
if t, _ := x.typ.Underlying().(*Slice); t != nil {
|
||||||
dst = t.elt
|
dst = t.elem
|
||||||
}
|
}
|
||||||
|
|
||||||
var y operand
|
var y operand
|
||||||
@ -277,7 +277,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
|
|||||||
src = Typ[Byte]
|
src = Typ[Byte]
|
||||||
}
|
}
|
||||||
case *Slice:
|
case *Slice:
|
||||||
src = t.elt
|
src = t.elem
|
||||||
}
|
}
|
||||||
|
|
||||||
if dst == nil || src == nil {
|
if dst == nil || src == nil {
|
||||||
|
@ -237,7 +237,7 @@ func (check *checker) argument(sig *Signature, i int, x *operand, passSlice bool
|
|||||||
}
|
}
|
||||||
} else if sig.isVariadic && i >= n-1 {
|
} else if sig.isVariadic && i >= n-1 {
|
||||||
// use the variadic parameter slice's element type
|
// use the variadic parameter slice's element type
|
||||||
typ = typ.(*Slice).elt
|
typ = typ.(*Slice).elem
|
||||||
}
|
}
|
||||||
|
|
||||||
if !check.assignment(x, typ) && x.mode != invalid {
|
if !check.assignment(x, typ) && x.mode != invalid {
|
||||||
|
@ -135,7 +135,7 @@ func isPointer(typ Type) bool {
|
|||||||
|
|
||||||
func isBytesOrRunes(typ Type) bool {
|
func isBytesOrRunes(typ Type) bool {
|
||||||
if s, ok := typ.(*Slice); ok {
|
if s, ok := typ.(*Slice); ok {
|
||||||
t, ok := s.elt.Underlying().(*Basic)
|
t, ok := s.elem.Underlying().(*Basic)
|
||||||
return ok && (t.kind == Byte || t.kind == Rune)
|
return ok && (t.kind == Byte || t.kind == Rune)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -193,7 +193,7 @@ func writeTuple(buf *bytes.Buffer, tup *Tuple, isVariadic bool) {
|
|||||||
typ := v.typ
|
typ := v.typ
|
||||||
if isVariadic && i == len(tup.vars)-1 {
|
if isVariadic && i == len(tup.vars)-1 {
|
||||||
buf.WriteString("...")
|
buf.WriteString("...")
|
||||||
typ = typ.(*Slice).elt
|
typ = typ.(*Slice).elem
|
||||||
}
|
}
|
||||||
writeType(buf, typ)
|
writeType(buf, typ)
|
||||||
}
|
}
|
||||||
@ -231,11 +231,11 @@ func writeType(buf *bytes.Buffer, typ Type) {
|
|||||||
|
|
||||||
case *Array:
|
case *Array:
|
||||||
fmt.Fprintf(buf, "[%d]", t.len)
|
fmt.Fprintf(buf, "[%d]", t.len)
|
||||||
writeType(buf, t.elt)
|
writeType(buf, t.elem)
|
||||||
|
|
||||||
case *Slice:
|
case *Slice:
|
||||||
buf.WriteString("[]")
|
buf.WriteString("[]")
|
||||||
writeType(buf, t.elt)
|
writeType(buf, t.elem)
|
||||||
|
|
||||||
case *Struct:
|
case *Struct:
|
||||||
buf.WriteString("struct{")
|
buf.WriteString("struct{")
|
||||||
@ -300,7 +300,7 @@ func writeType(buf *bytes.Buffer, typ Type) {
|
|||||||
buf.WriteString("map[")
|
buf.WriteString("map[")
|
||||||
writeType(buf, t.key)
|
writeType(buf, t.key)
|
||||||
buf.WriteByte(']')
|
buf.WriteByte(']')
|
||||||
writeType(buf, t.elt)
|
writeType(buf, t.elem)
|
||||||
|
|
||||||
case *Chan:
|
case *Chan:
|
||||||
var s string
|
var s string
|
||||||
@ -313,7 +313,7 @@ func writeType(buf *bytes.Buffer, typ Type) {
|
|||||||
s = "chan "
|
s = "chan "
|
||||||
}
|
}
|
||||||
buf.WriteString(s)
|
buf.WriteString(s)
|
||||||
writeType(buf, t.elt)
|
writeType(buf, t.elem)
|
||||||
|
|
||||||
case *Named:
|
case *Named:
|
||||||
s := "<Named w/o object>"
|
s := "<Named w/o object>"
|
||||||
|
@ -108,7 +108,7 @@ func (check *checker) unary(x *operand, op token.Token) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
x.mode = commaok
|
x.mode = commaok
|
||||||
x.typ = typ.elt
|
x.typ = typ.elem
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -987,7 +987,7 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||||||
// We have an "open" [...]T array type.
|
// We have an "open" [...]T array type.
|
||||||
// Create a new ArrayType with unknown length (-1)
|
// Create a new ArrayType with unknown length (-1)
|
||||||
// and finish setting it up after analyzing the literal.
|
// and finish setting it up after analyzing the literal.
|
||||||
typ = &Array{len: -1, elt: check.typ(atyp.Elt, nil, false)}
|
typ = &Array{len: -1, elem: check.typ(atyp.Elt, nil, false)}
|
||||||
openArray = true
|
openArray = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1070,14 +1070,14 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case *Array:
|
case *Array:
|
||||||
n := check.indexedElts(e.Elts, utyp.elt, utyp.len)
|
n := check.indexedElts(e.Elts, utyp.elem, utyp.len)
|
||||||
// if we have an "open" [...]T array, set the length now that we know it
|
// if we have an "open" [...]T array, set the length now that we know it
|
||||||
if openArray {
|
if openArray {
|
||||||
utyp.len = n
|
utyp.len = n
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Slice:
|
case *Slice:
|
||||||
check.indexedElts(e.Elts, utyp.elt, -1)
|
check.indexedElts(e.Elts, utyp.elem, -1)
|
||||||
|
|
||||||
case *Map:
|
case *Map:
|
||||||
visited := make(map[interface{}]bool, len(e.Elts))
|
visited := make(map[interface{}]bool, len(e.Elts))
|
||||||
@ -1101,10 +1101,10 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||||||
}
|
}
|
||||||
visited[x.val] = true
|
visited[x.val] = true
|
||||||
}
|
}
|
||||||
check.exprWithHint(x, kv.Value, utyp.elt)
|
check.exprWithHint(x, kv.Value, utyp.elem)
|
||||||
if !check.assignment(x, utyp.elt) {
|
if !check.assignment(x, utyp.elem) {
|
||||||
if x.mode != invalid {
|
if x.mode != invalid {
|
||||||
check.errorf(x.pos(), "cannot use %s as %s value in map literal", x, utyp.elt)
|
check.errorf(x.pos(), "cannot use %s as %s value in map literal", x, utyp.elem)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -1154,20 +1154,20 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||||||
if x.mode != variable {
|
if x.mode != variable {
|
||||||
x.mode = value
|
x.mode = value
|
||||||
}
|
}
|
||||||
x.typ = typ.elt
|
x.typ = typ.elem
|
||||||
|
|
||||||
case *Pointer:
|
case *Pointer:
|
||||||
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
|
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
|
||||||
valid = true
|
valid = true
|
||||||
length = typ.len
|
length = typ.len
|
||||||
x.mode = variable
|
x.mode = variable
|
||||||
x.typ = typ.elt
|
x.typ = typ.elem
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Slice:
|
case *Slice:
|
||||||
valid = true
|
valid = true
|
||||||
x.mode = variable
|
x.mode = variable
|
||||||
x.typ = typ.elt
|
x.typ = typ.elem
|
||||||
|
|
||||||
case *Map:
|
case *Map:
|
||||||
var key operand
|
var key operand
|
||||||
@ -1179,7 +1179,7 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||||||
goto Error
|
goto Error
|
||||||
}
|
}
|
||||||
x.mode = mapindex
|
x.mode = mapindex
|
||||||
x.typ = typ.elt
|
x.typ = typ.elem
|
||||||
x.expr = e
|
x.expr = e
|
||||||
return expression
|
return expression
|
||||||
}
|
}
|
||||||
@ -1231,14 +1231,14 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||||||
check.invalidOp(x.pos(), "cannot slice %s (value not addressable)", x)
|
check.invalidOp(x.pos(), "cannot slice %s (value not addressable)", x)
|
||||||
goto Error
|
goto Error
|
||||||
}
|
}
|
||||||
x.typ = &Slice{elt: typ.elt}
|
x.typ = &Slice{elem: typ.elem}
|
||||||
|
|
||||||
case *Pointer:
|
case *Pointer:
|
||||||
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
|
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
|
||||||
valid = true
|
valid = true
|
||||||
length = typ.len
|
length = typ.len
|
||||||
x.mode = variable
|
x.mode = variable
|
||||||
x.typ = &Slice{elt: typ.elt}
|
x.typ = &Slice{elem: typ.elem}
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Slice:
|
case *Slice:
|
||||||
|
@ -415,12 +415,12 @@ func (p *gcParser) parseArrayType() Type {
|
|||||||
// "[" already consumed and lookahead known not to be "]"
|
// "[" already consumed and lookahead known not to be "]"
|
||||||
lit := p.expect(scanner.Int)
|
lit := p.expect(scanner.Int)
|
||||||
p.expect(']')
|
p.expect(']')
|
||||||
elt := p.parseType()
|
elem := p.parseType()
|
||||||
n, err := strconv.ParseInt(lit, 10, 64)
|
n, err := strconv.ParseInt(lit, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.error(err)
|
p.error(err)
|
||||||
}
|
}
|
||||||
return &Array{len: n, elt: elt}
|
return &Array{len: n, elem: elem}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MapType = "map" "[" Type "]" Type .
|
// MapType = "map" "[" Type "]" Type .
|
||||||
@ -430,8 +430,8 @@ func (p *gcParser) parseMapType() Type {
|
|||||||
p.expect('[')
|
p.expect('[')
|
||||||
key := p.parseType()
|
key := p.parseType()
|
||||||
p.expect(']')
|
p.expect(']')
|
||||||
elt := p.parseType()
|
elem := p.parseType()
|
||||||
return &Map{key: key, elt: elt}
|
return &Map{key: key, elem: elem}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name = identifier | "?" | QualifiedName .
|
// Name = identifier | "?" | QualifiedName .
|
||||||
@ -550,7 +550,7 @@ func (p *gcParser) parseParameter() (par *Var, isVariadic bool) {
|
|||||||
}
|
}
|
||||||
typ := p.parseType()
|
typ := p.parseType()
|
||||||
if isVariadic {
|
if isVariadic {
|
||||||
typ = &Slice{elt: typ}
|
typ = &Slice{elem: typ}
|
||||||
}
|
}
|
||||||
// ignore argument tag (e.g. "noescape")
|
// ignore argument tag (e.g. "noescape")
|
||||||
if p.tok == scanner.String {
|
if p.tok == scanner.String {
|
||||||
@ -657,8 +657,8 @@ func (p *gcParser) parseChanType() Type {
|
|||||||
p.expectKeyword("chan")
|
p.expectKeyword("chan")
|
||||||
dir = ast.RECV
|
dir = ast.RECV
|
||||||
}
|
}
|
||||||
elt := p.parseType()
|
elem := p.parseType()
|
||||||
return &Chan{dir: dir, elt: elt}
|
return &Chan{dir: dir, elem: elem}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type =
|
// Type =
|
||||||
@ -700,7 +700,7 @@ func (p *gcParser) parseType() Type {
|
|||||||
if p.tok == ']' {
|
if p.tok == ']' {
|
||||||
// SliceType
|
// SliceType
|
||||||
p.next()
|
p.next()
|
||||||
return &Slice{elt: p.parseType()}
|
return &Slice{elem: p.parseType()}
|
||||||
}
|
}
|
||||||
return p.parseArrayType()
|
return p.parseArrayType()
|
||||||
case '*':
|
case '*':
|
||||||
|
@ -232,7 +232,7 @@ func (x *operand) isAssignableTo(conf *Config, T Type) bool {
|
|||||||
// type, x's type V and T have identical element types,
|
// type, x's type V and T have identical element types,
|
||||||
// and at least one of V or T is not a named type
|
// and at least one of V or T is not a named type
|
||||||
if Vc, ok := Vu.(*Chan); ok && Vc.dir == ast.SEND|ast.RECV {
|
if Vc, ok := Vu.(*Chan); ok && Vc.dir == ast.SEND|ast.RECV {
|
||||||
if Tc, ok := Tu.(*Chan); ok && IsIdentical(Vc.elt, Tc.elt) {
|
if Tc, ok := Tu.(*Chan); ok && IsIdentical(Vc.elem, Tc.elem) {
|
||||||
return !isNamed(V) || !isNamed(T)
|
return !isNamed(V) || !isNamed(T)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func isComparable(typ Type) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
case *Array:
|
case *Array:
|
||||||
return isComparable(t.elt)
|
return isComparable(t.elem)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -139,13 +139,13 @@ func isIdenticalInternal(x, y Type, p *ifacePair) bool {
|
|||||||
// Two array types are identical if they have identical element types
|
// Two array types are identical if they have identical element types
|
||||||
// and the same array length.
|
// and the same array length.
|
||||||
if y, ok := y.(*Array); ok {
|
if y, ok := y.(*Array); ok {
|
||||||
return x.len == y.len && isIdenticalInternal(x.elt, y.elt, p)
|
return x.len == y.len && isIdenticalInternal(x.elem, y.elem, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Slice:
|
case *Slice:
|
||||||
// Two slice types are identical if they have identical element types.
|
// Two slice types are identical if they have identical element types.
|
||||||
if y, ok := y.(*Slice); ok {
|
if y, ok := y.(*Slice); ok {
|
||||||
return isIdenticalInternal(x.elt, y.elt, p)
|
return isIdenticalInternal(x.elem, y.elem, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Struct:
|
case *Struct:
|
||||||
@ -256,14 +256,14 @@ func isIdenticalInternal(x, y Type, p *ifacePair) bool {
|
|||||||
case *Map:
|
case *Map:
|
||||||
// Two map types are identical if they have identical key and value types.
|
// Two map types are identical if they have identical key and value types.
|
||||||
if y, ok := y.(*Map); ok {
|
if y, ok := y.(*Map); ok {
|
||||||
return isIdenticalInternal(x.key, y.key, p) && isIdenticalInternal(x.elt, y.elt, p)
|
return isIdenticalInternal(x.key, y.key, p) && isIdenticalInternal(x.elem, y.elem, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Chan:
|
case *Chan:
|
||||||
// Two channel types are identical if they have identical value types
|
// Two channel types are identical if they have identical value types
|
||||||
// and the same direction.
|
// and the same direction.
|
||||||
if y, ok := y.(*Chan); ok {
|
if y, ok := y.(*Chan); ok {
|
||||||
return x.dir == y.dir && isIdenticalInternal(x.elt, y.elt, p)
|
return x.dir == y.dir && isIdenticalInternal(x.elem, y.elem, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Named:
|
case *Named:
|
||||||
|
@ -46,7 +46,7 @@ func (s *StdSizes) Alignof(T Type) int64 {
|
|||||||
case *Array:
|
case *Array:
|
||||||
// spec: "For a variable x of array type: unsafe.Alignof(x)
|
// spec: "For a variable x of array type: unsafe.Alignof(x)
|
||||||
// is the same as unsafe.Alignof(x[0]), but at least 1."
|
// is the same as unsafe.Alignof(x[0]), but at least 1."
|
||||||
return s.Alignof(t.elt)
|
return s.Alignof(t.elem)
|
||||||
case *Struct:
|
case *Struct:
|
||||||
// spec: "For a variable x of struct type: unsafe.Alignof(x)
|
// spec: "For a variable x of struct type: unsafe.Alignof(x)
|
||||||
// is the largest of the values unsafe.Alignof(x.f) for each
|
// is the largest of the values unsafe.Alignof(x.f) for each
|
||||||
@ -92,8 +92,8 @@ func (s *StdSizes) Sizeof(T Type) int64 {
|
|||||||
return s.WordSize * 2
|
return s.WordSize * 2
|
||||||
}
|
}
|
||||||
case *Array:
|
case *Array:
|
||||||
a := s.Alignof(t.elt)
|
a := s.Alignof(t.elem)
|
||||||
z := s.Sizeof(t.elt)
|
z := s.Sizeof(t.elem)
|
||||||
return align(z, a) * t.len // may be 0
|
return align(z, a) * t.len // may be 0
|
||||||
case *Slice:
|
case *Slice:
|
||||||
return s.WordSize * 3
|
return s.WordSize * 3
|
||||||
|
@ -202,7 +202,7 @@ func (check *checker) stmt(ctxt stmtContext, s ast.Stmt) {
|
|||||||
if ch.mode == invalid || x.mode == invalid {
|
if ch.mode == invalid || x.mode == invalid {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if tch, ok := ch.typ.Underlying().(*Chan); !ok || tch.dir&ast.SEND == 0 || !check.assignment(&x, tch.elt) {
|
if tch, ok := ch.typ.Underlying().(*Chan); !ok || tch.dir&ast.SEND == 0 || !check.assignment(&x, tch.elem) {
|
||||||
if x.mode != invalid {
|
if x.mode != invalid {
|
||||||
check.invalidOp(ch.pos(), "cannot send %s to channel %s", &x, &ch)
|
check.invalidOp(ch.pos(), "cannot send %s to channel %s", &x, &ch)
|
||||||
}
|
}
|
||||||
@ -524,20 +524,20 @@ func (check *checker) stmt(ctxt stmtContext, s ast.Stmt) {
|
|||||||
}
|
}
|
||||||
case *Array:
|
case *Array:
|
||||||
key = Typ[Int]
|
key = Typ[Int]
|
||||||
val = typ.elt
|
val = typ.elem
|
||||||
case *Slice:
|
case *Slice:
|
||||||
key = Typ[Int]
|
key = Typ[Int]
|
||||||
val = typ.elt
|
val = typ.elem
|
||||||
case *Pointer:
|
case *Pointer:
|
||||||
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
|
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
|
||||||
key = Typ[Int]
|
key = Typ[Int]
|
||||||
val = typ.elt
|
val = typ.elem
|
||||||
}
|
}
|
||||||
case *Map:
|
case *Map:
|
||||||
key = typ.key
|
key = typ.key
|
||||||
val = typ.elt
|
val = typ.elem
|
||||||
case *Chan:
|
case *Chan:
|
||||||
key = typ.elt
|
key = typ.elem
|
||||||
val = Typ[Invalid]
|
val = Typ[Invalid]
|
||||||
if typ.dir&ast.RECV == 0 {
|
if typ.dir&ast.RECV == 0 {
|
||||||
check.errorf(x.pos(), "cannot range over send-only channel %s", &x)
|
check.errorf(x.pos(), "cannot range over send-only channel %s", &x)
|
||||||
|
@ -101,8 +101,8 @@ func (b *Basic) Name() string { return b.name }
|
|||||||
|
|
||||||
// An Array represents an array type.
|
// An Array represents an array type.
|
||||||
type Array struct {
|
type Array struct {
|
||||||
len int64
|
len int64
|
||||||
elt Type
|
elem Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewArray returns a new array type for the given element type and length.
|
// NewArray returns a new array type for the given element type and length.
|
||||||
@ -112,18 +112,18 @@ func NewArray(elem Type, len int64) *Array { return &Array{len, elem} }
|
|||||||
func (a *Array) Len() int64 { return a.len }
|
func (a *Array) Len() int64 { return a.len }
|
||||||
|
|
||||||
// Elem returns element type of array a.
|
// Elem returns element type of array a.
|
||||||
func (a *Array) Elem() Type { return a.elt }
|
func (a *Array) Elem() Type { return a.elem }
|
||||||
|
|
||||||
// A Slice represents a slice type.
|
// A Slice represents a slice type.
|
||||||
type Slice struct {
|
type Slice struct {
|
||||||
elt Type
|
elem Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSlice returns a new slice type for the given element type.
|
// NewSlice returns a new slice type for the given element type.
|
||||||
func NewSlice(elem Type) *Slice { return &Slice{elem} }
|
func NewSlice(elem Type) *Slice { return &Slice{elem} }
|
||||||
|
|
||||||
// Elem returns the element type of slice s.
|
// Elem returns the element type of slice s.
|
||||||
func (s *Slice) Elem() Type { return s.elt }
|
func (s *Slice) Elem() Type { return s.elem }
|
||||||
|
|
||||||
// A Struct represents a struct type.
|
// A Struct represents a struct type.
|
||||||
type Struct struct {
|
type Struct struct {
|
||||||
@ -263,7 +263,7 @@ func (t *Interface) Method(i int) *Func { return t.allMethods[i] }
|
|||||||
|
|
||||||
// A Map represents a map type.
|
// A Map represents a map type.
|
||||||
type Map struct {
|
type Map struct {
|
||||||
key, elt Type
|
key, elem Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMap returns a new map for the given key and element types.
|
// NewMap returns a new map for the given key and element types.
|
||||||
@ -275,12 +275,12 @@ func NewMap(key, elem Type) *Map {
|
|||||||
func (m *Map) Key() Type { return m.key }
|
func (m *Map) Key() Type { return m.key }
|
||||||
|
|
||||||
// Elem returns the element type of map m.
|
// Elem returns the element type of map m.
|
||||||
func (m *Map) Elem() Type { return m.elt }
|
func (m *Map) Elem() Type { return m.elem }
|
||||||
|
|
||||||
// A Chan represents a channel type.
|
// A Chan represents a channel type.
|
||||||
type Chan struct {
|
type Chan struct {
|
||||||
dir ast.ChanDir
|
dir ast.ChanDir
|
||||||
elt Type
|
elem Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewChan returns a new channel type for the given direction and element type.
|
// NewChan returns a new channel type for the given direction and element type.
|
||||||
@ -292,7 +292,7 @@ func NewChan(dir ast.ChanDir, elem Type) *Chan {
|
|||||||
func (c *Chan) Dir() ast.ChanDir { return c.dir }
|
func (c *Chan) Dir() ast.ChanDir { return c.dir }
|
||||||
|
|
||||||
// Elem returns the element type of channel c.
|
// Elem returns the element type of channel c.
|
||||||
func (c *Chan) Elem() Type { return c.elt }
|
func (c *Chan) Elem() Type { return c.elem }
|
||||||
|
|
||||||
// A Named represents a named type.
|
// A Named represents a named type.
|
||||||
type Named struct {
|
type Named struct {
|
||||||
|
@ -265,7 +265,7 @@ func (check *checker) typInternal(e ast.Expr, def *Named, cycleOk bool) Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typ.len = n
|
typ.len = n
|
||||||
typ.elt = check.typ(e.Elt, nil, cycleOk)
|
typ.elem = check.typ(e.Elt, nil, cycleOk)
|
||||||
return typ
|
return typ
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -274,7 +274,7 @@ func (check *checker) typInternal(e ast.Expr, def *Named, cycleOk bool) Type {
|
|||||||
def.underlying = typ
|
def.underlying = typ
|
||||||
}
|
}
|
||||||
|
|
||||||
typ.elt = check.typ(e.Elt, nil, true)
|
typ.elem = check.typ(e.Elt, nil, true)
|
||||||
return typ
|
return typ
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +309,7 @@ func (check *checker) typInternal(e ast.Expr, def *Named, cycleOk bool) Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typ.key = check.typ(e.Key, nil, true)
|
typ.key = check.typ(e.Key, nil, true)
|
||||||
typ.elt = check.typ(e.Value, nil, true)
|
typ.elem = check.typ(e.Value, nil, true)
|
||||||
|
|
||||||
// spec: "The comparison operators == and != must be fully defined
|
// spec: "The comparison operators == and != must be fully defined
|
||||||
// for operands of the key type; thus the key type must not be a
|
// for operands of the key type; thus the key type must not be a
|
||||||
@ -329,7 +329,7 @@ func (check *checker) typInternal(e ast.Expr, def *Named, cycleOk bool) Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typ.dir = e.Dir
|
typ.dir = e.Dir
|
||||||
typ.elt = check.typ(e.Value, nil, true)
|
typ.elem = check.typ(e.Value, nil, true)
|
||||||
return typ
|
return typ
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -401,7 +401,7 @@ func (check *checker) collectParams(scope *Scope, list *ast.FieldList, variadicO
|
|||||||
// For a variadic function, change the last parameter's type from T to []T.
|
// For a variadic function, change the last parameter's type from T to []T.
|
||||||
if isVariadic && len(params) > 0 {
|
if isVariadic && len(params) > 0 {
|
||||||
last := params[len(params)-1]
|
last := params[len(params)-1]
|
||||||
last.typ = &Slice{elt: last.typ}
|
last.typ = &Slice{elem: last.typ}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user