]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types: use nopos instead of token.NoPos to match types2
authorRobert Griesemer <gri@golang.org>
Mon, 9 Jan 2023 21:54:50 +0000 (13:54 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 17 Jan 2023 19:55:37 +0000 (19:55 +0000)
This will simplify the generation of go/types files from types2 files.

Change-Id: Ie9c8061346cff098cb884908c7eb569267886594
Reviewed-on: https://go-review.googlesource.com/c/go/+/461082
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>

26 files changed:
src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/check.go
src/go/types/api_test.go
src/go/types/assignments.go
src/go/types/builtins.go
src/go/types/call.go
src/go/types/check.go
src/go/types/context_test.go
src/go/types/errors.go
src/go/types/errors_test.go
src/go/types/eval.go
src/go/types/eval_test.go
src/go/types/infer.go
src/go/types/instantiate.go
src/go/types/instantiate_test.go
src/go/types/interface.go
src/go/types/issues_test.go
src/go/types/object.go
src/go/types/object_test.go
src/go/types/operand.go
src/go/types/package.go
src/go/types/predicates.go
src/go/types/resolver.go
src/go/types/signature.go
src/go/types/typeterm_test.go
src/go/types/universe.go

index fe84720052eecc91635ec681d1ea328fe8414904..af315e7b7082cb0b7ef5b76efd643b04e974e71e 100644 (file)
@@ -18,6 +18,9 @@ import (
        . "cmd/compile/internal/types2"
 )
 
+// nopos indicates an unknown position
+var nopos syntax.Pos
+
 func parse(path, src string) (*syntax.File, error) {
        errh := func(error) {} // dummy error handler so that parsing continues in presence of errors
        return syntax.Parse(syntax.NewFileBase(path), strings.NewReader(src), errh, nil, 0)
@@ -1821,8 +1824,6 @@ func F(){
        }
 }
 
-var nopos syntax.Pos
-
 // newDefined creates a new defined type named T with the given underlying type.
 func newDefined(underlying Type) *Named {
        tname := NewTypeName(nopos, nil, "T", nil)
index c495293009d4e9191f411047a956b56998f504ae..33b57c0c2c1e5544334e61951c969f84ca0a1876 100644 (file)
@@ -14,6 +14,7 @@ import (
        . "internal/types/errors"
 )
 
+// nopos indicates an unknown position
 var nopos syntax.Pos
 
 // debugging/development support
index 98ef6c423f5c4913a49d552bba0e63bf371e89a7..df6d0c3d4405d4fd3b44dc97a518fa60f8ed22f2 100644 (file)
@@ -21,6 +21,9 @@ import (
        . "go/types"
 )
 
+// nopos indicates an unknown position
+var nopos token.Pos
+
 func parse(fset *token.FileSet, filename, src string) (*ast.File, error) {
        return parser.ParseFile(fset, filename, src, 0)
 }
@@ -1816,7 +1819,7 @@ func F(){
 // newDefined creates a new defined type named T with the given underlying type.
 // Helper function for use with TestIncompleteInterfaces only.
 func newDefined(underlying Type) *Named {
-       tname := NewTypeName(token.NoPos, nil, "T", nil)
+       tname := NewTypeName(nopos, nil, "T", nil)
        return NewNamed(tname, underlying, nil)
 }
 
@@ -1932,7 +1935,7 @@ func TestIdentical_issue15173(t *testing.T) {
 }
 
 func TestIdenticalUnions(t *testing.T) {
-       tname := NewTypeName(token.NoPos, nil, "myInt", nil)
+       tname := NewTypeName(nopos, nil, "myInt", nil)
        myInt := NewNamed(tname, Typ[Int], nil)
        tmap := map[string]*Term{
                "int":     NewTerm(false, Typ[Int]),
index 4d5acb10520c962f9fc4e71762c404fa466e97b2..ab244418447dfeefd7cdd493251e2b68ef31dfa6 100644 (file)
@@ -9,7 +9,6 @@ package types
 import (
        "fmt"
        "go/ast"
-       "go/token"
        . "internal/types/errors"
        "strings"
 )
@@ -335,8 +334,8 @@ func (check *Checker) initVars(lhs []*Var, origRHS []ast.Expr, returnStmt ast.St
                                at = rhs[len(rhs)-1].expr // report at last value
                        }
                        err := newErrorf(at, WrongResultCount, "%s return values", qualifier)
-                       err.errorf(token.NoPos, "have %s", check.typesSummary(operandTypes(rhs), false))
-                       err.errorf(token.NoPos, "want %s", check.typesSummary(varTypes(lhs), false))
+                       err.errorf(nopos, "have %s", check.typesSummary(operandTypes(rhs), false))
+                       err.errorf(nopos, "want %s", check.typesSummary(varTypes(lhs), false))
                        check.report(err)
                        return
                }
index d3bca606b2f29e2dfc049f28229cb21e8251392a..fb3be066a15cfd2993fbe8f629c334c1c5df7d3a 100644 (file)
@@ -968,7 +968,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId)
                // Construct a suitable new type parameter for the result type.
                // The type parameter is placed in the current package so export/import
                // works as expected.
-               tpar := NewTypeName(token.NoPos, check.pkg, tp.obj.name, nil)
+               tpar := NewTypeName(nopos, check.pkg, tp.obj.name, nil)
                ptyp := check.newTypeParam(tpar, NewInterfaceType(nil, []Type{NewUnion(terms)})) // assigns type to tpar as a side-effect
                ptyp.index = tp.index
 
@@ -983,13 +983,13 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId)
 func makeSig(res Type, args ...Type) *Signature {
        list := make([]*Var, len(args))
        for i, param := range args {
-               list[i] = NewVar(token.NoPos, nil, "", Default(param))
+               list[i] = NewVar(nopos, nil, "", Default(param))
        }
        params := NewTuple(list...)
        var result *Tuple
        if res != nil {
                assert(!isUntyped(res))
-               result = NewTuple(NewVar(token.NoPos, nil, "", res))
+               result = NewTuple(NewVar(nopos, nil, "", res))
        }
        return &Signature{params: params, results: result}
 }
index f0d612d018f9d075d025bfb989ad30d090ae2ee0..53c5a64fb0510534c9167214297de3873b52605a 100644 (file)
@@ -391,8 +391,8 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
                        params = sig.params.vars
                }
                err := newErrorf(at, WrongArgCount, "%s arguments in call to %s", qualifier, call.Fun)
-               err.errorf(token.NoPos, "have %s", check.typesSummary(operandTypes(args), false))
-               err.errorf(token.NoPos, "want %s", check.typesSummary(varTypes(params), sig.variadic))
+               err.errorf(nopos, "have %s", check.typesSummary(operandTypes(args), false))
+               err.errorf(nopos, "want %s", check.typesSummary(varTypes(params), sig.variadic))
                check.report(err)
                return
        }
@@ -799,7 +799,7 @@ func (check *Checker) useLHS(arg ...ast.Expr) {
                        if ident.Name == "_" {
                                continue
                        }
-                       if _, obj := check.scope.LookupParent(ident.Name, token.NoPos); obj != nil {
+                       if _, obj := check.scope.LookupParent(ident.Name, nopos); obj != nil {
                                // It's ok to mark non-local variables, but ignore variables
                                // from other packages to avoid potential race conditions with
                                // dot-imported variables.
index 76be49804248f675020bb9d45db7e30dc86acd5f..60d3e1ac4bcbc2545013f2ded8c6d1c4c23ac19d 100644 (file)
@@ -15,6 +15,9 @@ import (
        . "internal/types/errors"
 )
 
+// nopos indicates an unknown position
+var nopos token.Pos
+
 // debugging/development support
 const debug = false // leave on during development
 
@@ -378,7 +381,7 @@ func (check *Checker) processDelayed(top int) {
                        if a.desc != nil {
                                check.trace(a.desc.pos.Pos(), "-- "+a.desc.format, a.desc.args...)
                        } else {
-                               check.trace(token.NoPos, "-- delayed %p", a.f)
+                               check.trace(nopos, "-- delayed %p", a.f)
                        }
                }
                a.f() // may append to check.delayed
index ec3005020220683d7cc83fcd6ad45479438d7240..b323651e29de855a95182cf1b9e7807a8187ca1c 100644 (file)
@@ -5,7 +5,6 @@
 package types
 
 import (
-       "go/token"
        "testing"
 )
 
@@ -28,18 +27,18 @@ func TestContextHashCollisions(t *testing.T) {
        var nullaryP, nullaryQ, unaryP Type
        {
                // type nullaryP = func[P any]()
-               tparam := NewTypeParam(NewTypeName(token.NoPos, nil, "P", nil), &emptyInterface)
+               tparam := NewTypeParam(NewTypeName(nopos, nil, "P", nil), &emptyInterface)
                nullaryP = NewSignatureType(nil, nil, []*TypeParam{tparam}, nil, nil, false)
        }
        {
                // type nullaryQ = func[Q any]()
-               tparam := NewTypeParam(NewTypeName(token.NoPos, nil, "Q", nil), &emptyInterface)
+               tparam := NewTypeParam(NewTypeName(nopos, nil, "Q", nil), &emptyInterface)
                nullaryQ = NewSignatureType(nil, nil, []*TypeParam{tparam}, nil, nil, false)
        }
        {
                // type unaryP = func[P any](_ P)
-               tparam := NewTypeParam(NewTypeName(token.NoPos, nil, "P", nil), &emptyInterface)
-               params := NewTuple(NewVar(token.NoPos, nil, "_", tparam))
+               tparam := NewTypeParam(NewTypeName(nopos, nil, "P", nil), &emptyInterface)
+               params := NewTuple(NewVar(nopos, nil, "_", tparam))
                unaryP = NewSignatureType(nil, nil, []*TypeParam{tparam}, params, nil, false)
        }
 
index 4c4cd038149156e39084a2fa02607aec9506b4a3..95ee51e2cab70b55ab06b14dc341a5c87ae6a2e9 100644 (file)
@@ -54,7 +54,7 @@ func (err *error_) empty() bool {
 
 func (err *error_) pos() token.Pos {
        if err.empty() {
-               return token.NoPos
+               return nopos
        }
        return err.desc[0].posn.Pos()
 }
@@ -367,7 +367,7 @@ func spanOf(at positioner) posSpan {
                        pos := x.Pos()
                        return posSpan{pos, pos, x.expr.End()}
                }
-               return posSpan{token.NoPos, token.NoPos, token.NoPos}
+               return posSpan{nopos, nopos, nopos}
        default:
                pos := at.Pos()
                return posSpan{pos, pos, pos}
index 4b5dab68e4e0c7a457ea12b4b53dedeb26237d22..3fb9c55ac527e8caa4a87dc1d2d77f433218083c 100644 (file)
@@ -5,7 +5,6 @@
 package types
 
 import (
-       "go/token"
        "testing"
 )
 
@@ -17,13 +16,13 @@ func TestError(t *testing.T) {
        }
 
        want = "0: foo 42"
-       err.errorf(token.NoPos, "foo %d", 42)
+       err.errorf(nopos, "foo %d", 42)
        if got := err.String(); got != want {
                t.Errorf("simple error: got %q, want %q", got, want)
        }
 
        want = "0: foo 42\n\tbar 43"
-       err.errorf(token.NoPos, "bar %d", 43)
+       err.errorf(nopos, "bar %d", 43)
        if got := err.String(); got != want {
                t.Errorf("simple error: got %q, want %q", got, want)
        }
index 084f746fe671a82a1c8a43d2b54e10d5599e99ee..1e4d64fe96b2c3019989243d437dd6f8981a169a 100644 (file)
@@ -58,7 +58,7 @@ func CheckExpr(fset *token.FileSet, pkg *Package, pos token.Pos, expr ast.Expr,
        var scope *Scope
        if pkg == nil {
                scope = Universe
-               pos = token.NoPos
+               pos = nopos
        } else if !pos.IsValid() {
                scope = pkg.scope
        } else {
index b0745c16d9729b84b5e26853d7623ed94892ba7a..4e995afd7ed39dc8f0c2a2895a9f4108f6cc4779 100644 (file)
@@ -59,14 +59,14 @@ func testEval(t *testing.T, fset *token.FileSet, pkg *Package, pos token.Pos, ex
 func TestEvalBasic(t *testing.T) {
        fset := token.NewFileSet()
        for _, typ := range Typ[Bool : String+1] {
-               testEval(t, fset, nil, token.NoPos, typ.Name(), typ, "", "")
+               testEval(t, fset, nil, nopos, typ.Name(), typ, "", "")
        }
 }
 
 func TestEvalComposite(t *testing.T) {
        fset := token.NewFileSet()
        for _, test := range independentTestTypes {
-               testEval(t, fset, nil, token.NoPos, test.src, nil, test.str, "")
+               testEval(t, fset, nil, nopos, test.src, nil, test.str, "")
        }
 }
 
@@ -83,7 +83,7 @@ func TestEvalArith(t *testing.T) {
        }
        fset := token.NewFileSet()
        for _, test := range tests {
-               testEval(t, fset, nil, token.NoPos, test, Typ[UntypedBool], "", "true")
+               testEval(t, fset, nil, nopos, test, Typ[UntypedBool], "", "true")
        }
 }
 
index 4ce58fcbbcff38755eb0d5896180e8356e30bcb2..c1a1dd693baf70bc75d81de2deae74aed97f8da4 100644 (file)
@@ -9,7 +9,6 @@ package types
 
 import (
        "fmt"
-       "go/token"
        . "internal/types/errors"
        "strings"
 )
@@ -174,7 +173,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
        //           but that doesn't impact the isParameterized check for now).
        if params.Len() > 0 {
                smap := makeSubstMap(tparams, targs)
-               params = check.subst(token.NoPos, params, smap, nil, check.context()).(*Tuple)
+               params = check.subst(nopos, params, smap, nil, check.context()).(*Tuple)
        }
 
        // Unify parameter and argument types for generic parameters with typed arguments
@@ -618,7 +617,7 @@ func (check *Checker) inferB(posn positioner, tparams []*TypeParam, targs []Type
                n := 0
                for _, index := range dirty {
                        t0 := types[index]
-                       if t1 := check.subst(token.NoPos, t0, smap, nil, check.context()); t1 != t0 {
+                       if t1 := check.subst(nopos, t0, smap, nil, check.context()); t1 != t0 {
                                types[index] = t1
                                dirty[n] = index
                                n++
index 2cf48c17d298dcc1b39fb95ea634b6afb1e30e86..f1448d69d4bf2c4ea06d8d72673db2bf7dc1988f 100644 (file)
@@ -55,12 +55,12 @@ func Instantiate(ctxt *Context, orig Type, targs []Type, validate bool) (Type, e
                if len(targs) != len(tparams) {
                        return nil, fmt.Errorf("got %d type arguments but %s has %d type parameters", len(targs), orig, len(tparams))
                }
-               if i, err := (*Checker)(nil).verify(token.NoPos, tparams, targs, ctxt); err != nil {
+               if i, err := (*Checker)(nil).verify(nopos, tparams, targs, ctxt); err != nil {
                        return nil, &ArgumentError{i, err}
                }
        }
 
-       inst := (*Checker)(nil).instance(token.NoPos, orig, targs, nil, ctxt)
+       inst := (*Checker)(nil).instance(nopos, orig, targs, nil, ctxt)
        return inst, nil
 }
 
index 0b44a1a1d97d97a0fa4fbbfec1aa4a42e4fdce7c..8b551187bd9342569178b60c16b771740ed757db 100644 (file)
@@ -5,7 +5,6 @@
 package types_test
 
 import (
-       "go/token"
        . "go/types"
        "strings"
        "testing"
@@ -43,13 +42,13 @@ func TestInstantiateEquality(t *testing.T) {
                        // interface{interface{...}} is equivalent to interface{...}
                        "package equivalentinterfaces; type T[P any] int",
                        "T", []Type{
-                               NewInterfaceType([]*Func{NewFunc(token.NoPos, nil, "M", emptySignature)}, nil),
+                               NewInterfaceType([]*Func{NewFunc(nopos, nil, "M", emptySignature)}, nil),
                        },
                        "T", []Type{
                                NewInterfaceType(
                                        nil,
                                        []Type{
-                                               NewInterfaceType([]*Func{NewFunc(token.NoPos, nil, "M", emptySignature)}, nil),
+                                               NewInterfaceType([]*Func{NewFunc(nopos, nil, "M", emptySignature)}, nil),
                                        },
                                ),
                        },
index 83538d2885fb1e38a6d7a3fdb0302ac8f6fc7f17..f2bb15e84bad06f455222f685f53d840e3b60fa4 100644 (file)
@@ -26,7 +26,7 @@ type Interface struct {
 }
 
 // typeSet returns the type set for interface t.
-func (t *Interface) typeSet() *_TypeSet { return computeInterfaceTypeSet(t.check, token.NoPos, t) }
+func (t *Interface) typeSet() *_TypeSet { return computeInterfaceTypeSet(t.check, nopos, t) }
 
 // emptyInterface represents the empty (completed) interface
 var emptyInterface = Interface{complete: true, tset: &topTypeSet}
index bb6b4c316143004f2ce785ab1d1bb03685bb1d08..d1e78eded7c3891d1e4c2cf8ad3a699472993b79 100644 (file)
@@ -516,14 +516,14 @@ func TestIssue43088(t *testing.T) {
        //                 _ T2
        //         }
        // }
-       n1 := NewTypeName(token.NoPos, nil, "T1", nil)
+       n1 := NewTypeName(nopos, nil, "T1", nil)
        T1 := NewNamed(n1, nil, nil)
-       n2 := NewTypeName(token.NoPos, nil, "T2", nil)
+       n2 := NewTypeName(nopos, nil, "T2", nil)
        T2 := NewNamed(n2, nil, nil)
-       s1 := NewStruct([]*Var{NewField(token.NoPos, nil, "_", T2, false)}, nil)
+       s1 := NewStruct([]*Var{NewField(nopos, nil, "_", T2, false)}, nil)
        T1.SetUnderlying(s1)
-       s2 := NewStruct([]*Var{NewField(token.NoPos, nil, "_", T2, false)}, nil)
-       s3 := NewStruct([]*Var{NewField(token.NoPos, nil, "_", s2, false)}, nil)
+       s2 := NewStruct([]*Var{NewField(nopos, nil, "_", T2, false)}, nil)
+       s3 := NewStruct([]*Var{NewField(nopos, nil, "_", s2, false)}, nil)
        T2.SetUnderlying(s3)
 
        // These calls must terminate (no endless recursion).
@@ -644,7 +644,7 @@ func TestIssue50646(t *testing.T) {
 func TestIssue55030(t *testing.T) {
        // makeSig makes the signature func(typ...)
        makeSig := func(typ Type) {
-               par := NewVar(token.NoPos, nil, "", typ)
+               par := NewVar(nopos, nil, "", typ)
                params := NewTuple(par)
                NewSignatureType(nil, nil, nil, params, nil, true)
        }
@@ -658,22 +658,22 @@ func TestIssue55030(t *testing.T) {
 
        // P where P's core type is string
        {
-               P := NewTypeName(token.NoPos, nil, "P", nil) // [P string]
+               P := NewTypeName(nopos, nil, "P", nil) // [P string]
                makeSig(NewTypeParam(P, NewInterfaceType(nil, []Type{Typ[String]})))
        }
 
        // P where P's core type is an (unnamed) slice
        {
-               P := NewTypeName(token.NoPos, nil, "P", nil) // [P []int]
+               P := NewTypeName(nopos, nil, "P", nil) // [P []int]
                makeSig(NewTypeParam(P, NewInterfaceType(nil, []Type{NewSlice(Typ[Int])})))
        }
 
        // P where P's core type is bytestring (i.e., string or []byte)
        {
-               t1 := NewTerm(true, Typ[String])             // ~string
-               t2 := NewTerm(false, NewSlice(Typ[Byte]))    // []byte
-               u := NewUnion([]*Term{t1, t2})               // ~string | []byte
-               P := NewTypeName(token.NoPos, nil, "P", nil) // [P ~string | []byte]
+               t1 := NewTerm(true, Typ[String])          // ~string
+               t2 := NewTerm(false, NewSlice(Typ[Byte])) // []byte
+               u := NewUnion([]*Term{t1, t2})            // ~string | []byte
+               P := NewTypeName(nopos, nil, "P", nil)    // [P ~string | []byte]
                makeSig(NewTypeParam(P, NewInterfaceType(nil, []Type{u})))
        }
 }
index 6e63948680b12533b2500f37ff4ccac6ab927701..3013552bf567366d126cc17f5327228c67863aaa 100644 (file)
@@ -189,7 +189,7 @@ type PkgName struct {
 // NewPkgName returns a new PkgName object representing an imported package.
 // The remaining arguments set the attributes found with all Objects.
 func NewPkgName(pos token.Pos, pkg *Package, name string, imported *Package) *PkgName {
-       return &PkgName{object{nil, pos, pkg, name, Typ[Invalid], 0, black, token.NoPos}, imported, false}
+       return &PkgName{object{nil, pos, pkg, name, Typ[Invalid], 0, black, nopos}, imported, false}
 }
 
 // Imported returns the package that was imported.
@@ -205,7 +205,7 @@ type Const struct {
 // NewConst returns a new constant with value val.
 // The remaining arguments set the attributes found with all Objects.
 func NewConst(pos token.Pos, pkg *Package, name string, typ Type, val constant.Value) *Const {
-       return &Const{object{nil, pos, pkg, name, typ, 0, colorFor(typ), token.NoPos}, val}
+       return &Const{object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, val}
 }
 
 // Val returns the constant's value.
@@ -226,7 +226,7 @@ type TypeName struct {
 // argument for NewNamed, which will set the TypeName's type as a side-
 // effect.
 func NewTypeName(pos token.Pos, pkg *Package, name string, typ Type) *TypeName {
-       return &TypeName{object{nil, pos, pkg, name, typ, 0, colorFor(typ), token.NoPos}}
+       return &TypeName{object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}}
 }
 
 // _NewTypeNameLazy returns a new defined type like NewTypeName, but it
@@ -275,19 +275,19 @@ type Var struct {
 // NewVar returns a new variable.
 // The arguments set the attributes found with all Objects.
 func NewVar(pos token.Pos, pkg *Package, name string, typ Type) *Var {
-       return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), token.NoPos}}
+       return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}}
 }
 
 // NewParam returns a new variable representing a function parameter.
 func NewParam(pos token.Pos, pkg *Package, name string, typ Type) *Var {
-       return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), token.NoPos}, used: true} // parameters are always 'used'
+       return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, used: true} // parameters are always 'used'
 }
 
 // NewField returns a new variable representing a struct field.
 // For embedded fields, the name is the unqualified type name
 // under which the field is accessible.
 func NewField(pos token.Pos, pkg *Package, name string, typ Type, embedded bool) *Var {
-       return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), token.NoPos}, embedded: embedded, isField: true}
+       return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, embedded: embedded, isField: true}
 }
 
 // Anonymous reports whether the variable is an embedded field.
@@ -333,7 +333,7 @@ func NewFunc(pos token.Pos, pkg *Package, name string, sig *Signature) *Func {
        if sig != nil {
                typ = sig
        }
-       return &Func{object{nil, pos, pkg, name, typ, 0, colorFor(typ), token.NoPos}, false, nil}
+       return &Func{object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, false, nil}
 }
 
 // FullName returns the package- or receiver-type-qualified name of
index 60e7a84ca6c69abc0b741d8fd21e3c2e26a7171f..118669b3326e54e0c6cca7d6ff82d0b2fe63299f 100644 (file)
@@ -131,7 +131,7 @@ func TestObjectString(t *testing.T) {
                        t.Errorf("%s: invalid object path %s", test.src, test.obj)
                        continue
                }
-               _, obj := pkg.Scope().LookupParent(names[0], token.NoPos)
+               _, obj := pkg.Scope().LookupParent(names[0], nopos)
                if obj == nil {
                        t.Errorf("%s: %s not found", test.src, names[0])
                        continue
index 819c99e684cc5ba23d0674f00d8583733e0332b0..a23e195ad6bd636930c91f8351e331f2dc388d4d 100644 (file)
@@ -59,11 +59,11 @@ type operand struct {
 }
 
 // Pos returns the position of the expression corresponding to x.
-// If x is invalid the position is token.NoPos.
+// If x is invalid the position is nopos.
 func (x *operand) Pos() token.Pos {
        // x.expr may not be set if x is invalid
        if x.expr == nil {
-               return token.NoPos
+               return nopos
        }
        return x.expr.Pos()
 }
index 2b72ff15092ece316a9dd39da8200cec81a5aa1b..201f603234459d1a0a4dd65edc753ad17061d395 100644 (file)
@@ -6,7 +6,6 @@ package types
 
 import (
        "fmt"
-       "go/token"
 )
 
 // A Package describes a Go package.
@@ -23,7 +22,7 @@ type Package struct {
 // NewPackage returns a new Package for the given package path and name.
 // The package is not complete and contains no explicit imports.
 func NewPackage(path, name string) *Package {
-       scope := NewScope(Universe, token.NoPos, token.NoPos, fmt.Sprintf("package %q", path))
+       scope := NewScope(Universe, nopos, nopos, fmt.Sprintf("package %q", path))
        return &Package{path: path, name: name, scope: scope}
 }
 
index e9a0e438d888afcb2ff1294a5d7ec0bf08bb6894..b26b5beb9cb90dd5e13b300015c3cfcf18dfc328 100644 (file)
@@ -6,8 +6,6 @@
 
 package types
 
-import "go/token"
-
 // The isX predicates below report whether t is an X.
 // If t is a type parameter the result is false; i.e.,
 // these predicates don't look inside a type parameter.
@@ -312,14 +310,14 @@ func identical(x, y Type, cmpTags bool, p *ifacePair) bool {
 
                        // Constraints must be pair-wise identical, after substitution.
                        for i, xtparam := range xtparams {
-                               ybound := check.subst(token.NoPos, ytparams[i].bound, smap, nil, ctxt)
+                               ybound := check.subst(nopos, ytparams[i].bound, smap, nil, ctxt)
                                if !identical(xtparam.bound, ybound, cmpTags, p) {
                                        return false
                                }
                        }
 
-                       yparams = check.subst(token.NoPos, y.params, smap, nil, ctxt).(*Tuple)
-                       yresults = check.subst(token.NoPos, y.results, smap, nil, ctxt).(*Tuple)
+                       yparams = check.subst(nopos, y.params, smap, nil, ctxt).(*Tuple)
+                       yresults = check.subst(nopos, y.results, smap, nil, ctxt).(*Tuple)
                }
 
                return x.variadic == y.variadic &&
@@ -331,8 +329,8 @@ func identical(x, y Type, cmpTags bool, p *ifacePair) bool {
                        // TODO(rfindley): can this be reached during type checking? If so,
                        // consider passing a type set map.
                        unionSets := make(map[*Union]*_TypeSet)
-                       xset := computeUnionTypeSet(nil, unionSets, token.NoPos, x)
-                       yset := computeUnionTypeSet(nil, unionSets, token.NoPos, y)
+                       xset := computeUnionTypeSet(nil, unionSets, nopos, x)
+                       yset := computeUnionTypeSet(nil, unionSets, nopos, y)
                        return xset.terms.equal(yset.terms)
                }
 
index 075bd912610202f8647d930fb1aac8306ce07bb4..f1038c151fd60daa5cafec2bff1785bd6b2a4e50 100644 (file)
@@ -118,7 +118,7 @@ func (check *Checker) declarePkgObj(ident *ast.Ident, obj Object, d *declInfo) {
                return
        }
 
-       check.declare(check.pkg.scope, ident, obj, token.NoPos)
+       check.declare(check.pkg.scope, ident, obj, nopos)
        check.objMap[obj] = d
        obj.setOrder(uint32(len(check.objMap)))
 }
@@ -338,7 +338,7 @@ func (check *Checker) collectObjects() {
                                } else {
                                        // declare imported package object in file scope
                                        // (no need to provide s.Name since we called check.recordDef earlier)
-                                       check.declare(fileScope, nil, pkgName, token.NoPos)
+                                       check.declare(fileScope, nil, pkgName, nopos)
                                }
                        case constDecl:
                                // declare all constants
@@ -425,7 +425,7 @@ func (check *Checker) collectObjects() {
                                                        check.softErrorf(obj, MissingInitBody, "missing function body")
                                                }
                                        } else {
-                                               check.declare(pkg.scope, d.decl.Name, obj, token.NoPos)
+                                               check.declare(pkg.scope, d.decl.Name, obj, nopos)
                                        }
                                } else {
                                        // method
index 83460eaf1f7f80043fb7c5292abc36fb966cb87e..5986ec83a7cc7b1d89f623169eb22fa93d3a0776 100644 (file)
@@ -7,7 +7,6 @@ package types
 import (
        "fmt"
        "go/ast"
-       "go/token"
        . "internal/types/errors"
 )
 
@@ -180,7 +179,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast
        // Value (non-type) parameters' scope starts in the function body. Use a temporary scope for their
        // declarations and then squash that scope into the parent scope (and report any redeclarations at
        // that time).
-       scope := NewScope(check.scope, token.NoPos, token.NoPos, "function body (temp. scope)")
+       scope := NewScope(check.scope, nopos, nopos, "function body (temp. scope)")
        recvList, _ := check.collectParams(scope, recvPar, false)
        params, variadic := check.collectParams(scope, ftyp.Params, true)
        results, _ := check.collectParams(scope, ftyp.Results, false)
@@ -197,7 +196,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast
                switch len(recvList) {
                case 0:
                        // error reported by resolver
-                       recv = NewParam(token.NoPos, nil, "", Typ[Invalid]) // ignore recv below
+                       recv = NewParam(nopos, nil, "", Typ[Invalid]) // ignore recv below
                default:
                        // more than one receiver
                        check.error(recvList[len(recvList)-1], InvalidRecv, "method has multiple receivers")
index 24a14102d0a0cb29d7308d1b3f2b09215205adc3..683b95ee56f2faee5d136aab7fea9dae3859e580 100644 (file)
@@ -5,13 +5,12 @@
 package types
 
 import (
-       "go/token"
        "strings"
        "testing"
 )
 
 var myInt = func() Type {
-       tname := NewTypeName(token.NoPos, nil, "myInt", nil)
+       tname := NewTypeName(nopos, nil, "myInt", nil)
        return NewNamed(tname, Typ[Int], nil)
 }()
 
index 9103fca713e686eeefcfff0b538baa25493ccd74..8860aadfcab0192a5aebbc057db6cf148ed8e826 100644 (file)
@@ -8,7 +8,6 @@ package types
 
 import (
        "go/constant"
-       "go/token"
        "strings"
 )
 
@@ -73,33 +72,33 @@ var aliases = [...]*Basic{
 
 func defPredeclaredTypes() {
        for _, t := range Typ {
-               def(NewTypeName(token.NoPos, nil, t.name, t))
+               def(NewTypeName(nopos, nil, t.name, t))
        }
        for _, t := range aliases {
-               def(NewTypeName(token.NoPos, nil, t.name, t))
+               def(NewTypeName(nopos, nil, t.name, t))
        }
 
        // type any = interface{}
        // Note: don't use &emptyInterface for the type of any. Using a unique
        // pointer allows us to detect any and format it as "any" rather than
        // interface{}, which clarifies user-facing error messages significantly.
-       def(NewTypeName(token.NoPos, nil, "any", &Interface{complete: true, tset: &topTypeSet}))
+       def(NewTypeName(nopos, nil, "any", &Interface{complete: true, tset: &topTypeSet}))
 
        // type error interface{ Error() string }
        {
-               obj := NewTypeName(token.NoPos, nil, "error", nil)
+               obj := NewTypeName(nopos, nil, "error", nil)
                obj.setColor(black)
                typ := NewNamed(obj, nil, nil)
 
                // error.Error() string
-               recv := NewVar(token.NoPos, nil, "", typ)
-               res := NewVar(token.NoPos, nil, "", Typ[String])
+               recv := NewVar(nopos, nil, "", typ)
+               res := NewVar(nopos, nil, "", Typ[String])
                sig := NewSignatureType(recv, nil, nil, nil, NewTuple(res), false)
-               err := NewFunc(token.NoPos, nil, "Error", sig)
+               err := NewFunc(nopos, nil, "Error", sig)
 
                // interface{ Error() string }
                ityp := &Interface{methods: []*Func{err}, complete: true}
-               computeInterfaceTypeSet(nil, token.NoPos, ityp) // prevent races due to lazy computation of tset
+               computeInterfaceTypeSet(nil, nopos, ityp) // prevent races due to lazy computation of tset
 
                typ.SetUnderlying(ityp)
                def(obj)
@@ -107,7 +106,7 @@ func defPredeclaredTypes() {
 
        // type comparable interface{} // marked as comparable
        {
-               obj := NewTypeName(token.NoPos, nil, "comparable", nil)
+               obj := NewTypeName(nopos, nil, "comparable", nil)
                obj.setColor(black)
                typ := NewNamed(obj, nil, nil)
 
@@ -131,7 +130,7 @@ var predeclaredConsts = [...]struct {
 
 func defPredeclaredConsts() {
        for _, c := range predeclaredConsts {
-               def(NewConst(token.NoPos, nil, c.name, Typ[c.kind], c.val))
+               def(NewConst(nopos, nil, c.name, Typ[c.kind], c.val))
        }
 }
 
@@ -234,7 +233,7 @@ func DefPredeclaredTestFuncs() {
 }
 
 func init() {
-       Universe = NewScope(nil, token.NoPos, token.NoPos, "universe")
+       Universe = NewScope(nil, nopos, nopos, "universe")
        Unsafe = NewPackage("unsafe", "unsafe")
        Unsafe.complete = true