mirror of
https://github.com/golang/go
synced 2024-11-26 19:41:19 -07:00
go/types: cleanup panic calls
This is a port of CL 339969 to go/types. It differs slightly in errors.go, due to the differing API. Change-Id: Ie2bf84ebf312ea3872ee6706615dfc6169a32405 Reviewed-on: https://go-review.googlesource.com/c/go/+/342431 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
11a1f37b07
commit
a192ef8ac4
@ -339,7 +339,7 @@ func (check *Checker) validType(typ Type, path []Object) typeInfo {
|
|||||||
// cycle detected
|
// cycle detected
|
||||||
for i, tn := range path {
|
for i, tn := range path {
|
||||||
if t.obj.pkg != check.pkg {
|
if t.obj.pkg != check.pkg {
|
||||||
panic("internal error: type cycle via package-external type")
|
panic("type cycle via package-external type")
|
||||||
}
|
}
|
||||||
if tn == t.obj {
|
if tn == t.obj {
|
||||||
check.cycleError(path[i:])
|
check.cycleError(path[i:])
|
||||||
@ -347,7 +347,7 @@ func (check *Checker) validType(typ Type, path []Object) typeInfo {
|
|||||||
return t.info
|
return t.info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("internal error: cycle start not found")
|
panic("cycle start not found")
|
||||||
}
|
}
|
||||||
return t.info
|
return t.info
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (check *Checker) sprintf(format string, args ...interface{}) string {
|
|||||||
case nil:
|
case nil:
|
||||||
arg = "<nil>"
|
arg = "<nil>"
|
||||||
case operand:
|
case operand:
|
||||||
panic("internal error: should always pass *operand")
|
panic("got operand instead of *operand")
|
||||||
case *operand:
|
case *operand:
|
||||||
arg = operandString(a, check.qualifier)
|
arg = operandString(a, check.qualifier)
|
||||||
case token.Pos:
|
case token.Pos:
|
||||||
@ -236,7 +236,7 @@ func (s atPos) Pos() token.Pos {
|
|||||||
func spanOf(at positioner) posSpan {
|
func spanOf(at positioner) posSpan {
|
||||||
switch x := at.(type) {
|
switch x := at.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
panic("internal error: nil")
|
panic("nil positioner")
|
||||||
case posSpan:
|
case posSpan:
|
||||||
return x
|
return x
|
||||||
case ast.Node:
|
case ast.Node:
|
||||||
|
@ -320,7 +320,7 @@ func (check *Checker) missingMethod(V Type, T *Interface, static bool) (method,
|
|||||||
return m, f
|
return m, f
|
||||||
}
|
}
|
||||||
if ftyp.TParams().Len() > 0 {
|
if ftyp.TParams().Len() > 0 {
|
||||||
panic("internal error: method with type parameters")
|
panic("method with type parameters")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the methods have type parameters we don't care whether they
|
// If the methods have type parameters we don't care whether they
|
||||||
@ -372,7 +372,7 @@ func (check *Checker) missingMethod(V Type, T *Interface, static bool) (method,
|
|||||||
return m, f
|
return m, f
|
||||||
}
|
}
|
||||||
if ftyp.TParams().Len() > 0 {
|
if ftyp.TParams().Len() > 0 {
|
||||||
panic("internal error: method with type parameters")
|
panic("method with type parameters")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If V is a (instantiated) generic type, its methods are still
|
// If V is a (instantiated) generic type, its methods are still
|
||||||
|
@ -33,7 +33,7 @@ type Named struct {
|
|||||||
// The underlying type must not be a *Named.
|
// The underlying type must not be a *Named.
|
||||||
func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named {
|
func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named {
|
||||||
if _, ok := underlying.(*Named); ok {
|
if _, ok := underlying.(*Named); ok {
|
||||||
panic("types.NewNamed: underlying type must not be *Named")
|
panic("underlying type must not be *Named")
|
||||||
}
|
}
|
||||||
return (*Checker)(nil).newNamed(obj, nil, underlying, nil, methods)
|
return (*Checker)(nil).newNamed(obj, nil, underlying, nil, methods)
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ func (check *Checker) newNamed(obj *TypeName, orig *Named, underlying Type, tpar
|
|||||||
check.later(func() {
|
check.later(func() {
|
||||||
switch typ.under().(type) {
|
switch typ.under().(type) {
|
||||||
case *Named:
|
case *Named:
|
||||||
panic("internal error: unexpanded underlying type")
|
panic("unexpanded underlying type")
|
||||||
}
|
}
|
||||||
typ.check = nil
|
typ.check = nil
|
||||||
})
|
})
|
||||||
@ -144,10 +144,10 @@ func (t *Named) Method(i int) *Func { return t.load().methods[i] }
|
|||||||
// SetUnderlying sets the underlying type and marks t as complete.
|
// SetUnderlying sets the underlying type and marks t as complete.
|
||||||
func (t *Named) SetUnderlying(underlying Type) {
|
func (t *Named) SetUnderlying(underlying Type) {
|
||||||
if underlying == nil {
|
if underlying == nil {
|
||||||
panic("types.Named.SetUnderlying: underlying type must not be nil")
|
panic("underlying type must not be nil")
|
||||||
}
|
}
|
||||||
if _, ok := underlying.(*Named); ok {
|
if _, ok := underlying.(*Named); ok {
|
||||||
panic("types.Named.SetUnderlying: underlying type must not be *Named")
|
panic("underlying type must not be *Named")
|
||||||
}
|
}
|
||||||
t.load().underlying = underlying
|
t.load().underlying = underlying
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ func (n0 *Named) under() Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if n0.check == nil {
|
if n0.check == nil {
|
||||||
panic("internal error: Named.check == nil but type is incomplete")
|
panic("Named.check == nil but type is incomplete")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invariant: after this point n0 as well as any named types in its
|
// Invariant: after this point n0 as well as any named types in its
|
||||||
@ -246,7 +246,7 @@ func (n0 *Named) under() Type {
|
|||||||
// Also, doing so would lead to a race condition (was issue #31749).
|
// Also, doing so would lead to a race condition (was issue #31749).
|
||||||
// Do this check always, not just in debug mode (it's cheap).
|
// Do this check always, not just in debug mode (it's cheap).
|
||||||
if n.obj.pkg != check.pkg {
|
if n.obj.pkg != check.pkg {
|
||||||
panic("internal error: imported type with unresolved underlying type")
|
panic("imported type with unresolved underlying type")
|
||||||
}
|
}
|
||||||
n.underlying = u
|
n.underlying = u
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,10 @@ func NewSignature(recv *Var, params, results *Tuple, variadic bool) *Signature {
|
|||||||
if variadic {
|
if variadic {
|
||||||
n := params.Len()
|
n := params.Len()
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
panic("types.NewSignature: variadic function must have at least one parameter")
|
panic("variadic function must have at least one parameter")
|
||||||
}
|
}
|
||||||
if _, ok := params.At(n - 1).typ.(*Slice); !ok {
|
if _, ok := params.At(n - 1).typ.(*Slice); !ok {
|
||||||
panic("types.NewSignature: variadic parameter must be of unnamed slice type")
|
panic("variadic parameter must be of unnamed slice type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &Signature{recv: recv, params: params, results: results, variadic: variadic}
|
return &Signature{recv: recv, params: params, results: results, variadic: variadic}
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body *ast.BlockStmt, iota constant.Value) {
|
func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body *ast.BlockStmt, iota constant.Value) {
|
||||||
if check.conf.IgnoreFuncBodies {
|
if check.conf.IgnoreFuncBodies {
|
||||||
panic("internal error: function body not ignored")
|
panic("function body not ignored")
|
||||||
}
|
}
|
||||||
|
|
||||||
if trace {
|
if trace {
|
||||||
|
@ -77,7 +77,7 @@ func (t *TypeParam) Constraint() Type {
|
|||||||
// SetConstraint sets the type constraint for t.
|
// SetConstraint sets the type constraint for t.
|
||||||
func (t *TypeParam) SetConstraint(bound Type) {
|
func (t *TypeParam) SetConstraint(bound Type) {
|
||||||
if bound == nil {
|
if bound == nil {
|
||||||
panic("types2.TypeParam.SetConstraint: bound must not be nil")
|
panic("nil constraint")
|
||||||
}
|
}
|
||||||
t.bound = bound
|
t.bound = bound
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ func bindTParams(list []*TypeName) *TypeParams {
|
|||||||
for i, tp := range list {
|
for i, tp := range list {
|
||||||
typ := tp.Type().(*TypeParam)
|
typ := tp.Type().(*TypeParam)
|
||||||
if typ.index >= 0 {
|
if typ.index >= 0 {
|
||||||
panic("internal error: type parameter bound more than once")
|
panic("type parameter bound more than once")
|
||||||
}
|
}
|
||||||
typ.index = i
|
typ.index = i
|
||||||
}
|
}
|
||||||
|
@ -323,10 +323,10 @@ func sortMethods(list []*Func) {
|
|||||||
|
|
||||||
func assertSortedMethods(list []*Func) {
|
func assertSortedMethods(list []*Func) {
|
||||||
if !debug {
|
if !debug {
|
||||||
panic("internal error: assertSortedMethods called outside debug mode")
|
panic("assertSortedMethods called outside debug mode")
|
||||||
}
|
}
|
||||||
if !sort.IsSorted(byUniqueMethodName(list)) {
|
if !sort.IsSorted(byUniqueMethodName(list)) {
|
||||||
panic("internal error: methods not sorted")
|
panic("methods not sorted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
|
|||||||
// Unions only appear as (syntactic) embedded elements
|
// Unions only appear as (syntactic) embedded elements
|
||||||
// in interfaces and syntactically cannot be empty.
|
// in interfaces and syntactically cannot be empty.
|
||||||
if t.NumTerms() == 0 {
|
if t.NumTerms() == 0 {
|
||||||
panic("internal error: empty union")
|
panic("empty union")
|
||||||
}
|
}
|
||||||
for i, t := range t.terms {
|
for i, t := range t.terms {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
@ -185,7 +185,7 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
|
|||||||
case RecvOnly:
|
case RecvOnly:
|
||||||
s = "<-chan "
|
s = "<-chan "
|
||||||
default:
|
default:
|
||||||
panic("unreachable")
|
unreachable()
|
||||||
}
|
}
|
||||||
buf.WriteString(s)
|
buf.WriteString(s)
|
||||||
if parens {
|
if parens {
|
||||||
@ -332,7 +332,7 @@ func writeTuple(buf *bytes.Buffer, tup *Tuple, variadic bool, qf Qualifier, visi
|
|||||||
// special case:
|
// special case:
|
||||||
// append(s, "foo"...) leads to signature func([]byte, string...)
|
// append(s, "foo"...) leads to signature func([]byte, string...)
|
||||||
if t := asBasic(typ); t == nil || t.kind != String {
|
if t := asBasic(typ); t == nil || t.kind != String {
|
||||||
panic("internal error: string type expected")
|
panic("expected string type")
|
||||||
}
|
}
|
||||||
writeType(buf, typ, qf, visited)
|
writeType(buf, typ, qf, visited)
|
||||||
buf.WriteString("...")
|
buf.WriteString("...")
|
||||||
|
@ -133,7 +133,7 @@ func overlappingTerm(terms []*term, y *term) int {
|
|||||||
// disjoint requires non-nil, non-top arguments
|
// disjoint requires non-nil, non-top arguments
|
||||||
if debug {
|
if debug {
|
||||||
if x == nil || x.typ == nil || y == nil || y.typ == nil {
|
if x == nil || x.typ == nil || y == nil || y.typ == nil {
|
||||||
panic("internal error: empty or top union term")
|
panic("empty or top union term")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !x.disjoint(y) {
|
if !x.disjoint(y) {
|
||||||
|
@ -259,6 +259,6 @@ func def(obj Object) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if scope.Insert(obj) != nil {
|
if scope.Insert(obj) != nil {
|
||||||
panic("internal error: double declaration")
|
panic("double declaration of predeclared identifier")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user