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) qualifier(pkg *Package) string {
33 func (check *Checker) sprintf(format string, args ...interface{}) string {
34 for i, arg := range args {
35 switch a := arg.(type) {
39 panic("internal error: should always pass *operand")
41 arg = operandString(a, check.qualifier)
43 arg = check.fset.Position(a).String()
47 arg = ObjectString(a, check.qualifier)
49 arg = TypeString(a, check.qualifier)
53 return fmt.Sprintf(format, args...)
56 func (check *Checker) trace(pos token.Pos, format string, args ...interface{}) {
57 fmt.Printf("%s:\t%s%s\n",
58 check.fset.Position(pos),
59 strings.Repeat(". ", check.indent),
60 check.sprintf(format, args...),
64 // dump is only needed for debugging
65 func (check *Checker) dump(format string, args ...interface{}) {
66 fmt.Println(check.sprintf(format, args...))
69 func (check *Checker) err(pos token.Pos, msg string, soft bool) {
70 err := Error{check.fset, pos, msg, soft}
71 if check.firstErr == nil {
76 panic(bailout{}) // report only first error
81 func (check *Checker) error(pos token.Pos, msg string) {
82 check.err(pos, msg, false)
85 func (check *Checker) errorf(pos token.Pos, format string, args ...interface{}) {
86 check.err(pos, check.sprintf(format, args...), false)
89 func (check *Checker) softErrorf(pos token.Pos, format string, args ...interface{}) {
90 check.err(pos, check.sprintf(format, args...), true)
93 func (check *Checker) invalidAST(pos token.Pos, format string, args ...interface{}) {
94 check.errorf(pos, "invalid AST: "+format, args...)
97 func (check *Checker) invalidArg(pos token.Pos, format string, args ...interface{}) {
98 check.errorf(pos, "invalid argument: "+format, args...)
101 func (check *Checker) invalidOp(pos token.Pos, format string, args ...interface{}) {
102 check.errorf(pos, "invalid operation: "+format, args...)