Skip to content

Commit

Permalink
[#873] fix json output of -compileonly (#874)
Browse files Browse the repository at this point in the history
The errorToJSON() method in shell/errors_to_json.go checks whether the error returned is a *parse.MultiError. However, rather than a pointer to a MultiError, an instance was being passed in. Updated the the instance methods of MultiError to take pointers as receivers to be in line with what was expected. This further required updating some other references.
  • Loading branch information
sblundy authored and xiaq committed Dec 9, 2019
1 parent d1ec850 commit d076f36
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cliedit/highlight/highlight.go
Expand Up @@ -26,7 +26,7 @@ func highlight(code string, dep Dep, lateCb func(styled.Text)) (styled.Text, []e

n, errParse := parse.AsChunk("[interactive]", code)
if errParse != nil {
for _, err := range errParse.(parse.MultiError).Entries {
for _, err := range errParse.(*parse.MultiError).Entries {
if err.Context.Begin != len(code) {
errors = append(errors, err)
}
Expand Down
2 changes: 1 addition & 1 deletion edit/edcore/edit.go
Expand Up @@ -273,7 +273,7 @@ func atEnd(e error, n int) bool {
switch e := e.(type) {
case *eval.CompilationError:
return e.Context.Begin == n
case parse.MultiError:
case *parse.MultiError:
for _, entry := range e.Entries {
if entry.Context.Begin != n {
return false
Expand Down
4 changes: 2 additions & 2 deletions parse/error.go
Expand Up @@ -23,7 +23,7 @@ func (me *MultiError) add(msg string, ctx *diag.SourceRange) {
}

// Error returns a string representation of the error.
func (me MultiError) Error() string {
func (me *MultiError) Error() string {
switch len(me.Entries) {
case 0:
return "no parse error"
Expand All @@ -44,7 +44,7 @@ func (me MultiError) Error() string {
}

// PPrint pretty-prints the error.
func (me MultiError) PPrint(indent string) string {
func (me *MultiError) PPrint(indent string) string {
switch len(me.Entries) {
case 0:
return "no parse error"
Expand Down
2 changes: 1 addition & 1 deletion parse/parse_test.go
Expand Up @@ -279,7 +279,7 @@ func TestParseError(t *testing.T) {
t.Errorf("Parse(%q) returns no error", tc.src)
continue
}
posErr0 := err.(MultiError).Entries[0]
posErr0 := err.(*MultiError).Entries[0]
if posErr0.Context.Begin != tc.pos {
t.Errorf("Parse(%q) first error begins at %d, want %d. Errors are:%s\n", tc.src, posErr0.Context.Begin, tc.pos, err)
}
Expand Down
2 changes: 1 addition & 1 deletion parse/parser.go
Expand Up @@ -65,7 +65,7 @@ func (ps *parser) done() {
// Assembles all parsing errors as one, or returns nil if there were no errors.
func (ps *parser) assembleError() error {
if len(ps.errors.Entries) > 0 {
return ps.errors
return &ps.errors
}
return nil
}
Expand Down

0 comments on commit d076f36

Please sign in to comment.