1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This file implements various error reporters.
18 panic("assertion failed")
26 func (check *Checker) sprintf(format string, args ...interface{}) string {
27 for i, arg := range args {
28 switch a := arg.(type) {
32 panic("internal error: should always pass *operand")
34 arg = operandString(check.pkg, a)
36 arg = check.fset.Position(a).String()
40 arg = ObjectString(check.pkg, a)
42 arg = TypeString(check.pkg, a)
46 return fmt.Sprintf(format, args...)
49 func (check *Checker) trace(pos token.Pos, format string, args ...interface{}) {
50 fmt.Printf("%s:\t%s%s\n",
51 check.fset.Position(pos),
52 strings.Repeat(". ", check.indent),
53 check.sprintf(format, args...),
57 // dump is only needed for debugging
58 func (check *Checker) dump(format string, args ...interface{}) {
59 fmt.Println(check.sprintf(format, args...))
62 func (check *Checker) err(pos token.Pos, msg string, soft bool) {
63 err := Error{check.fset, pos, msg, soft}
64 if check.firstErr == nil {
69 panic(bailout{}) // report only first error
74 func (check *Checker) error(pos token.Pos, msg string) {
75 check.err(pos, msg, false)
78 func (check *Checker) errorf(pos token.Pos, format string, args ...interface{}) {
79 check.err(pos, check.sprintf(format, args...), false)
82 func (check *Checker) softErrorf(pos token.Pos, format string, args ...interface{}) {
83 check.err(pos, check.sprintf(format, args...), true)
86 func (check *Checker) invalidAST(pos token.Pos, format string, args ...interface{}) {
87 check.errorf(pos, "invalid AST: "+format, args...)
90 func (check *Checker) invalidArg(pos token.Pos, format string, args ...interface{}) {
91 check.errorf(pos, "invalid argument: "+format, args...)
94 func (check *Checker) invalidOp(pos token.Pos, format string, args ...interface{}) {
95 check.errorf(pos, "invalid operation: "+format, args...)