-
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?
Improve compiler error reporting #3780
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3780 +/- ##
==========================================
- Coverage 83.09% 83.07% -0.02%
==========================================
Files 335 335
Lines 46873 46875 +2
==========================================
- Hits 38949 38942 -7
- Misses 6337 6344 +7
- Partials 1587 1589 +2 ☔ View full report in Codecov by Sentry. |
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.
A nice extension.
@@ -1158,7 +1159,8 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor { | |||
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 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.
@@ -1158,7 +1159,8 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor { | |||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I didn't find test cases covering this error so I didn't add any new test.
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
func TestLT(t *testing.T) { |
Use evalWithError
to check the compilation error.
Problem
The compiler may fail without informing where the error is coming from. I found at least two places that can be fixed.
Solution
Include the file line and position of the error message
Output example:
Note: I didn't find test cases covering this error so I didn't add any new test.