mirror of
https://github.com/golang/go
synced 2024-11-19 00:54:42 -07:00
go.tools/go/types: Provide explicit type checker Error.
R=adonovan CC=golang-dev https://golang.org/cl/20400044
This commit is contained in:
parent
03e3f0cf81
commit
fb0632eb7d
@ -23,6 +23,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
|
||||
@ -44,6 +45,20 @@ func Check(path string, fset *token.FileSet, files []*ast.File) (*Package, error
|
||||
return pkg, nil
|
||||
}
|
||||
|
||||
// An Error describes a type-checking error;
|
||||
// it implements the error interface.
|
||||
type Error struct {
|
||||
Fset *token.FileSet // file set for interpretation of Pos
|
||||
Pos token.Pos // error position
|
||||
Msg string // error message
|
||||
}
|
||||
|
||||
// Error returns an error string formatted as follows:
|
||||
// filename:line:column: message
|
||||
func (err Error) Error() string {
|
||||
return fmt.Sprintf("%s: %s", err.Fset.Position(err.Pos), err.Msg)
|
||||
}
|
||||
|
||||
// A Config specifies the configuration for type checking.
|
||||
// The zero value for Config is a ready-to-use default configuration.
|
||||
type Config struct {
|
||||
@ -66,9 +81,7 @@ type Config struct {
|
||||
Packages map[string]*Package
|
||||
|
||||
// If Error != nil, it is called with each error found
|
||||
// during type checking. The error strings of errors with
|
||||
// detailed position information are formatted as follows:
|
||||
// filename:line:column: message
|
||||
// during type checking; err has dynamic type Error.
|
||||
Error func(err error)
|
||||
|
||||
// If Import != nil, it is called for each imported package.
|
||||
|
@ -53,7 +53,8 @@ func (check *checker) dump(format string, args ...interface{}) {
|
||||
fmt.Println(check.sprintf(format, args...))
|
||||
}
|
||||
|
||||
func (check *checker) err(err error) {
|
||||
func (check *checker) err(pos token.Pos, msg string) {
|
||||
err := Error{check.fset, pos, msg}
|
||||
if check.firstErr == nil {
|
||||
check.firstErr = err
|
||||
}
|
||||
@ -65,7 +66,7 @@ func (check *checker) err(err error) {
|
||||
}
|
||||
|
||||
func (check *checker) errorf(pos token.Pos, format string, args ...interface{}) {
|
||||
check.err(fmt.Errorf("%s: %s", check.fset.Position(pos), check.sprintf(format, args...)))
|
||||
check.err(pos, check.sprintf(format, args...))
|
||||
}
|
||||
|
||||
func (check *checker) invalidAST(pos token.Pos, format string, args ...interface{}) {
|
||||
|
Loading…
Reference in New Issue
Block a user