-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve compiler error reporting #3780
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -913,7 +913,8 @@ | |||
case *ast.StarExpr: | ||||
_, ok := c.getStruct(c.typeOf(n.X)) | ||||
if !ok { | ||||
c.prog.Err = errors.New("dereferencing is only supported on structs") | ||||
pos := c.buildInfo.config.Fset.Position(n.Pos()) | ||||
c.prog.Err = fmt.Errorf("%s: dereferencing is only supported on structs", pos) | ||||
return nil | ||||
} | ||||
ast.Walk(c, n.X) | ||||
|
@@ -1158,7 +1159,8 @@ | |||
c.convertStruct(lit, true) | ||||
return nil | ||||
} | ||||
c.prog.Err = fmt.Errorf("'&' can be used only with struct literals") | ||||
pos := c.buildInfo.config.Fset.Position(n.Pos()) | ||||
c.prog.Err = fmt.Errorf("%s: '&' can be used only with struct literals", pos) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You may construct your own test-case. Take as a reference any compiler unit-test, e.g. neo-go/pkg/compiler/if_test.go Line 9 in 4d2b88d
Use |
||||
return nil | ||||
} | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a couple of places where the same pattern may be applied (e.g. 20 lines below, try to search for
c.prog.Err =
usages). Let's move it to a helper and apply it to all relevant places.