check.pop().setColor(black)
default:
- check.errorf(s, InvalidSyntaxTree, invalidAST+"unknown syntax.Decl node %T", s)
+ check.errorf(s, InvalidSyntaxTree, "unknown syntax.Decl node %T", s)
}
}
}
}
func (check *Checker) err(at poser, code Code, msg string, soft bool) {
- if code == 0 {
+ switch code {
+ case InvalidSyntaxTree:
+ msg = "invalid syntax tree: " + msg
+ case 0:
panic("no error code provided")
}
}
const (
- invalidAST = "invalid AST: "
invalidArg = "invalid argument: "
invalidOp = "invalid operation: "
)
return false
}
} else {
- check.errorf(x, InvalidSyntaxTree, invalidAST+"unknown operator %s", op)
+ check.errorf(x, InvalidSyntaxTree, "unknown operator %s", op)
return false
}
return true
x.mode = value
x.typ = sig
} else {
- check.errorf(e, InvalidSyntaxTree, invalidAST+"invalid function literal %v", e)
+ check.errorf(e, InvalidSyntaxTree, "invalid function literal %v", e)
goto Error
}
}
// x.(type) expressions are encoded via TypeSwitchGuards
if e.Type == nil {
- check.error(e, InvalidSyntaxTree, invalidAST+"invalid use of AssertExpr")
+ check.error(e, InvalidSyntaxTree, "invalid use of AssertExpr")
goto Error
}
T := check.varType(e.Type)
case *syntax.TypeSwitchGuard:
// x.(type) expressions are handled explicitly in type switches
- check.error(e, InvalidSyntaxTree, invalidAST+"use of .(type) outside type switch")
+ check.error(e, InvalidSyntaxTree, "use of .(type) outside type switch")
goto Error
case *syntax.CallExpr:
case *syntax.ListExpr:
// catch-all for unexpected expression lists
- check.error(e, InvalidSyntaxTree, invalidAST+"unexpected list of expressions")
+ check.error(e, InvalidSyntaxTree, "unexpected list of expressions")
goto Error
// case *syntax.UnaryExpr:
case *syntax.KeyValueExpr:
// key:value expressions are handled in composite literals
- check.error(e, InvalidSyntaxTree, invalidAST+"no key:value expected")
+ check.error(e, InvalidSyntaxTree, "no key:value expected")
goto Error
case *syntax.ArrayType, *syntax.SliceType, *syntax.StructType, *syntax.FuncType,
// spec: "Only the first index may be omitted; it defaults to 0."
if e.Full && (e.Index[1] == nil || e.Index[2] == nil) {
- check.error(e, InvalidSyntaxTree, invalidAST+"2nd and 3rd index required in 3-index slice")
+ check.error(e, InvalidSyntaxTree, "2nd and 3rd index required in 3-index slice")
x.mode = invalid
return
}
func (check *Checker) singleIndex(e *syntax.IndexExpr) syntax.Expr {
index := e.Index
if index == nil {
- check.errorf(e, InvalidSyntaxTree, invalidAST+"missing index for %s", e.X)
+ check.errorf(e, InvalidSyntaxTree, "missing index for %s", e.X)
return nil
}
if l, _ := index.(*syntax.ListExpr); l != nil {
if n := len(l.ElemList); n <= 1 {
- check.errorf(e, InvalidSyntaxTree, invalidAST+"invalid use of ListExpr for index expression %v with %d indices", e, n)
+ check.errorf(e, InvalidSyntaxTree, "invalid use of ListExpr for index expression %v with %d indices", e, n)
return nil
}
// len(l.ElemList) > 1
sig, _ := typ.(*Signature)
if sig == nil {
if typ != Typ[Invalid] {
- check.errorf(f.Type, InvalidSyntaxTree, invalidAST+"%s is not a method signature", typ)
+ check.errorf(f.Type, InvalidSyntaxTree, "%s is not a method signature", typ)
}
continue // ignore
}
}
default:
- check.errorf(s, InvalidSyntaxTree, invalidAST+"branch statement: %s %s", s.Tok, name)
+ check.errorf(s, InvalidSyntaxTree, "branch statement: %s %s", s.Tok, name)
return
}
obj.setOrder(uint32(len(check.objMap)))
default:
- check.errorf(s, InvalidSyntaxTree, invalidAST+"unknown syntax.Decl node %T", s)
+ check.errorf(s, InvalidSyntaxTree, "unknown syntax.Decl node %T", s)
}
}
}
case *syntax.BadExpr:
// ignore - error already reported by parser
case nil:
- check.error(ptyp, InvalidSyntaxTree, invalidAST+"parameterized receiver contains nil parameters")
+ check.error(ptyp, InvalidSyntaxTree, "parameterized receiver contains nil parameters")
default:
check.errorf(arg, BadDecl, "receiver type parameter %s must be an identifier", arg)
}
// named parameter
name := field.Name.Value
if name == "" {
- check.error(field.Name, InvalidSyntaxTree, invalidAST+"anonymous parameter")
+ check.error(field.Name, InvalidSyntaxTree, "anonymous parameter")
// ok to continue
}
par := NewParam(field.Name.Pos(), check.pkg, name, typ)
}
if named && anonymous {
- check.error(list[0], InvalidSyntaxTree, invalidAST+"list contains both named and anonymous parameters")
+ check.error(list[0], InvalidSyntaxTree, "list contains both named and anonymous parameters")
// ok to continue
}
if s.Rhs == nil {
// x++ or x--
if len(lhs) != 1 {
- check.errorf(s, InvalidSyntaxTree, invalidAST+"%s%s requires one operand", s.Op, s.Op)
+ check.errorf(s, InvalidSyntaxTree, "%s%s requires one operand", s.Op, s.Op)
return
}
var x operand
// goto's must have labels, should have been caught above
fallthrough
default:
- check.errorf(s, InvalidSyntaxTree, invalidAST+"branch statement: %s", s.Tok)
+ check.errorf(s, InvalidSyntaxTree, "branch statement: %s", s.Tok)
}
case *syntax.BlockStmt:
case *syntax.IfStmt, *syntax.BlockStmt:
check.stmt(inner, s.Else)
default:
- check.error(s.Else, InvalidSyntaxTree, invalidAST+"invalid else branch in if statement")
+ check.error(s.Else, InvalidSyntaxTree, "invalid else branch in if statement")
}
case *syntax.SwitchStmt:
check.stmt(inner, s.Body)
default:
- check.error(s, InvalidSyntaxTree, invalidAST+"invalid statement")
+ check.error(s, InvalidSyntaxTree, "invalid statement")
}
}
seen := make(valueMap) // map of seen case values to positions and types
for i, clause := range s.Body {
if clause == nil {
- check.error(clause, InvalidSyntaxTree, invalidAST+"incorrect expression switch case")
+ check.error(clause, InvalidSyntaxTree, "incorrect expression switch case")
continue
}
end := s.Rbrace
seen := make(map[Type]syntax.Expr) // map of seen types to positions
for i, clause := range s.Body {
if clause == nil {
- check.error(s, InvalidSyntaxTree, invalidAST+"incorrect type switch case")
+ check.error(s, InvalidSyntaxTree, "incorrect type switch case")
continue
}
end := s.Rbrace
var sValue, sExtra syntax.Expr
if p, _ := sKey.(*syntax.ListExpr); p != nil {
if len(p.ElemList) < 2 {
- check.error(s, InvalidSyntaxTree, invalidAST+"invalid lhs in range clause")
+ check.error(s, InvalidSyntaxTree, "invalid lhs in range clause")
return
}
// len(p.ElemList) >= 2
vars = append(vars, obj)
}
} else {
- check.errorf(lhs, InvalidSyntaxTree, invalidAST+"cannot declare %s", lhs)
+ check.errorf(lhs, InvalidSyntaxTree, "cannot declare %s", lhs)
obj = NewVar(lhs.Pos(), check.pkg, "_", nil) // dummy variable
}
pos := syntax.StartPos(f.Type)
name := embeddedFieldIdent(f.Type)
if name == nil {
- check.errorf(pos, InvalidSyntaxTree, invalidAST+"invalid embedded field type %s", f.Type)
+ check.errorf(pos, InvalidSyntaxTree, "invalid embedded field type %s", f.Type)
name = &syntax.Name{Value: "_"} // TODO(gri) need to set position to pos
addInvalid(name, pos)
continue
return val
}
}
- check.errorf(t, InvalidSyntaxTree, invalidAST+"incorrect tag syntax: %q", t.Value)
+ check.errorf(t, InvalidSyntaxTree, "incorrect tag syntax: %q", t.Value)
}
return ""
}
case syntax.RecvOnly:
dir = RecvOnly
default:
- check.errorf(e, InvalidSyntaxTree, invalidAST+"unknown channel direction %d", e.Dir)
+ check.errorf(e, InvalidSyntaxTree, "unknown channel direction %d", e.Dir)
// ok to continue
}
check.arityMatch(s, nil)
f(varDecl{s})
default:
- check.errorf(s, InvalidSyntaxTree, invalidAST+"invalid token %s", d.Tok)
+ check.errorf(s, InvalidSyntaxTree, "invalid token %s", d.Tok)
}
case *ast.TypeSpec:
f(typeDecl{s})
default:
- check.errorf(s, InvalidSyntaxTree, invalidAST+"unknown ast.Spec node %T", s)
+ check.errorf(s, InvalidSyntaxTree, "unknown ast.Spec node %T", s)
}
}
case *ast.FuncDecl:
f(funcDecl{d})
default:
- check.errorf(d, InvalidSyntaxTree, invalidAST+"unknown ast.Decl node %T", d)
+ check.errorf(d, InvalidSyntaxTree, "unknown ast.Decl node %T", d)
}
}
check.typeDecl(obj, d.spec, nil)
check.pop().setColor(black)
default:
- check.errorf(d.node(), InvalidSyntaxTree, invalidAST+"unknown ast.Decl node %T", d.node())
+ check.errorf(d.node(), InvalidSyntaxTree, "unknown ast.Decl node %T", d.node())
}
})
}
panic("empty error details")
}
- if errp.code == 0 {
+ msg := errp.msg(check.fset, check.qualifier)
+ switch errp.code {
+ case InvalidSyntaxTree:
+ msg = "invalid AST: " + msg
+ case 0:
panic("no error code provided")
}
e := Error{
Fset: check.fset,
Pos: span.pos,
- Msg: errp.msg(check.fset, check.qualifier),
+ Msg: msg,
Soft: errp.soft,
go116code: errp.code,
go116start: span.start,
}
const (
- invalidAST = "invalid AST: "
invalidArg = "invalid argument: "
invalidOp = "invalid operation: "
)
return false
}
} else {
- check.errorf(x, InvalidSyntaxTree, invalidAST+"unknown operator %s", op)
+ check.errorf(x, InvalidSyntaxTree, "unknown operator %s", op)
return false
}
return true
x.mode = value
x.typ = sig
} else {
- check.errorf(e, InvalidSyntaxTree, invalidAST+"invalid function literal %s", e)
+ check.errorf(e, InvalidSyntaxTree, "invalid function literal %s", e)
goto Error
}
case *ast.KeyValueExpr:
// key:value expressions are handled in composite literals
- check.error(e, InvalidSyntaxTree, invalidAST+"no key:value expected")
+ check.error(e, InvalidSyntaxTree, "no key:value expected")
goto Error
case *ast.ArrayType, *ast.StructType, *ast.FuncType,
// spec: "Only the first index may be omitted; it defaults to 0."
if e.Slice3 && (e.High == nil || e.Max == nil) {
- check.error(inNode(e, e.Rbrack), InvalidSyntaxTree, invalidAST+"2nd and 3rd index required in 3-index slice")
+ check.error(inNode(e, e.Rbrack), InvalidSyntaxTree, "2nd and 3rd index required in 3-index slice")
x.mode = invalid
return
}
// is reported and the result is nil.
func (check *Checker) singleIndex(expr *typeparams.IndexExpr) ast.Expr {
if len(expr.Indices) == 0 {
- check.errorf(expr.Orig, InvalidSyntaxTree, invalidAST+"index expression %v with 0 indices", expr)
+ check.errorf(expr.Orig, InvalidSyntaxTree, "index expression %v with 0 indices", expr)
return nil
}
if len(expr.Indices) > 1 {
sig, _ := typ.(*Signature)
if sig == nil {
if typ != Typ[Invalid] {
- check.errorf(f.Type, InvalidSyntaxTree, invalidAST+"%s is not a method signature", typ)
+ check.errorf(f.Type, InvalidSyntaxTree, "%s is not a method signature", typ)
}
continue // ignore
}
}
default:
- check.errorf(s, InvalidSyntaxTree, invalidAST+"branch statement: %s %s", s.Tok, name)
+ check.errorf(s, InvalidSyntaxTree, "branch statement: %s %s", s.Tok, name)
return
}
case *ast.BadExpr:
// ignore - error already reported by parser
case nil:
- check.error(ix.Orig, InvalidSyntaxTree, invalidAST+"parameterized receiver contains nil parameters")
+ check.error(ix.Orig, InvalidSyntaxTree, "parameterized receiver contains nil parameters")
default:
check.errorf(arg, BadDecl, "receiver type parameter %s must be an identifier", arg)
}
// named parameter
for _, name := range field.Names {
if name.Name == "" {
- check.error(name, InvalidSyntaxTree, invalidAST+"anonymous parameter")
+ check.error(name, InvalidSyntaxTree, "anonymous parameter")
// ok to continue
}
par := NewParam(name.Pos(), check.pkg, name.Name, typ)
}
if named && anonymous {
- check.error(list, InvalidSyntaxTree, invalidAST+"list contains both named and anonymous parameters")
+ check.error(list, InvalidSyntaxTree, "list contains both named and anonymous parameters")
// ok to continue
}
d = s
}
default:
- check.error(s, InvalidSyntaxTree, invalidAST+"case/communication clause expected")
+ check.error(s, InvalidSyntaxTree, "case/communication clause expected")
}
if d != nil {
if first != nil {
case token.DEC:
op = token.SUB
default:
- check.errorf(inNode(s, s.TokPos), InvalidSyntaxTree, invalidAST+"unknown inc/dec operation %s", s.Tok)
+ check.errorf(inNode(s, s.TokPos), InvalidSyntaxTree, "unknown inc/dec operation %s", s.Tok)
return
}
switch s.Tok {
case token.ASSIGN, token.DEFINE:
if len(s.Lhs) == 0 {
- check.error(s, InvalidSyntaxTree, invalidAST+"missing lhs in assignment")
+ check.error(s, InvalidSyntaxTree, "missing lhs in assignment")
return
}
if s.Tok == token.DEFINE {
}
op := assignOp(s.Tok)
if op == token.ILLEGAL {
- check.errorf(atPos(s.TokPos), InvalidSyntaxTree, invalidAST+"unknown assignment operation %s", s.Tok)
+ check.errorf(atPos(s.TokPos), InvalidSyntaxTree, "unknown assignment operation %s", s.Tok)
return
}
var x operand
check.error(s, MisplacedFallthrough, msg)
}
default:
- check.errorf(s, InvalidSyntaxTree, invalidAST+"branch statement: %s", s.Tok)
+ check.errorf(s, InvalidSyntaxTree, "branch statement: %s", s.Tok)
}
case *ast.BlockStmt:
case *ast.IfStmt, *ast.BlockStmt:
check.stmt(inner, s.Else)
default:
- check.error(s.Else, InvalidSyntaxTree, invalidAST+"invalid else branch in if statement")
+ check.error(s.Else, InvalidSyntaxTree, "invalid else branch in if statement")
}
case *ast.SwitchStmt:
for i, c := range s.Body.List {
clause, _ := c.(*ast.CaseClause)
if clause == nil {
- check.error(c, InvalidSyntaxTree, invalidAST+"incorrect expression switch case")
+ check.error(c, InvalidSyntaxTree, "incorrect expression switch case")
continue
}
check.caseValues(&x, clause.List, seen)
rhs = guard.X
case *ast.AssignStmt:
if len(guard.Lhs) != 1 || guard.Tok != token.DEFINE || len(guard.Rhs) != 1 {
- check.error(s, InvalidSyntaxTree, invalidAST+"incorrect form of type switch guard")
+ check.error(s, InvalidSyntaxTree, "incorrect form of type switch guard")
return
}
lhs, _ = guard.Lhs[0].(*ast.Ident)
if lhs == nil {
- check.error(s, InvalidSyntaxTree, invalidAST+"incorrect form of type switch guard")
+ check.error(s, InvalidSyntaxTree, "incorrect form of type switch guard")
return
}
rhs = guard.Rhs[0]
default:
- check.error(s, InvalidSyntaxTree, invalidAST+"incorrect form of type switch guard")
+ check.error(s, InvalidSyntaxTree, "incorrect form of type switch guard")
return
}
// rhs must be of the form: expr.(type) and expr must be an ordinary interface
expr, _ := rhs.(*ast.TypeAssertExpr)
if expr == nil || expr.Type != nil {
- check.error(s, InvalidSyntaxTree, invalidAST+"incorrect form of type switch guard")
+ check.error(s, InvalidSyntaxTree, "incorrect form of type switch guard")
return
}
var x operand
for _, s := range s.Body.List {
clause, _ := s.(*ast.CaseClause)
if clause == nil {
- check.error(s, InvalidSyntaxTree, invalidAST+"incorrect type switch case")
+ check.error(s, InvalidSyntaxTree, "incorrect type switch case")
continue
}
// Check each type in this type switch case.
vars = append(vars, obj)
}
} else {
- check.errorf(lhs, InvalidSyntaxTree, invalidAST+"cannot declare %s", lhs)
+ check.errorf(lhs, InvalidSyntaxTree, "cannot declare %s", lhs)
obj = NewVar(lhs.Pos(), check.pkg, "_", nil) // dummy variable
}
check.stmt(inner, s.Body)
default:
- check.error(s, InvalidSyntaxTree, invalidAST+"invalid statement")
+ check.error(s, InvalidSyntaxTree, "invalid statement")
}
}
pos := f.Type.Pos()
name := embeddedFieldIdent(f.Type)
if name == nil {
- check.errorf(f.Type, InvalidSyntaxTree, invalidAST+"embedded field type %s has no name", f.Type)
+ check.errorf(f.Type, InvalidSyntaxTree, "embedded field type %s has no name", f.Type)
name = ast.NewIdent("_")
name.NamePos = pos
addInvalid(name, pos)
return val
}
}
- check.errorf(t, InvalidSyntaxTree, invalidAST+"incorrect tag syntax: %q", t.Value)
+ check.errorf(t, InvalidSyntaxTree, "incorrect tag syntax: %q", t.Value)
}
return ""
}
case ast.RECV:
dir = RecvOnly
default:
- check.errorf(e, InvalidSyntaxTree, invalidAST+"unknown channel direction %d", e.Dir)
+ check.errorf(e, InvalidSyntaxTree, "unknown channel direction %d", e.Dir)
// ok to continue
}