lang: ast, gapi, interfaces, parser: Print line numbers on error
This adds an initial implementation of printing line numbers on type unification errors. It also attempts to print a visual position indicator for most scenarios. This patch was started by Felix Frank and finished by James Shubin. Co-authored-by: Felix Frank <Felix.Frank.de@gmail.com>
This commit is contained in:
@@ -134,8 +134,15 @@ func (obj *FastInvariantSolver) Solve(ctx context.Context, data *unification.Dat
|
||||
if err := unificationUtil.Unify(x.Expect, x.Actual); err != nil {
|
||||
// Storing the Expr with this invariant is so that we
|
||||
// can generate this more helpful error message here.
|
||||
// TODO: Improve this error message!
|
||||
return nil, errwrap.Wrapf(err, "unify error with: %s", x.Expr)
|
||||
displayer, ok := x.Node.(interfaces.TextDisplayer)
|
||||
if !ok {
|
||||
obj.Logf("not displayable: %v\n", x.Node)
|
||||
return nil, errwrap.Wrapf(err, "unify error with: %s", x.Expr)
|
||||
}
|
||||
if highlight := displayer.HighlightText(); highlight != "" {
|
||||
obj.Logf("%s: %s", err.Error(), highlight)
|
||||
}
|
||||
return nil, fmt.Errorf("%s: %s", err.Error(), displayer.Byline())
|
||||
}
|
||||
if obj.Debug {
|
||||
e1, e2 := unificationUtil.Extract(x.Expect), unificationUtil.Extract(x.Actual)
|
||||
|
||||
@@ -859,6 +859,11 @@ func TestUnification1(t *testing.T) {
|
||||
|
||||
data := &interfaces.Data{
|
||||
// TODO: add missing fields here if/when needed
|
||||
Metadata: &interfaces.Metadata{},
|
||||
SourceFinder: func(string) ([]byte, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
},
|
||||
|
||||
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
|
||||
Logf: func(format string, v ...interface{}) {
|
||||
t.Logf(fmt.Sprintf("test #%d", index)+": ast: "+format, v...)
|
||||
|
||||
Reference in New Issue
Block a user