Skip to content
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

avm: preserve line/column for assembler warnings #5796

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ type SourceLocation struct {
type OpStream struct {
Version uint64
Trace *strings.Builder
Warnings []error // informational warnings, shouldn't stop assembly
Warnings []sourceError // informational warnings, shouldn't stop assembly
jasonpaulos marked this conversation as resolved.
Show resolved Hide resolved
Errors []sourceError // errors that should prevent final assembly
Program []byte // Final program bytes. Will stay nil if any errors

Expand Down Expand Up @@ -2694,7 +2694,7 @@ func (ops *OpStream) record(se *sourceError) {
}

func (ops *OpStream) warn(t token, format string, a ...interface{}) {
warning := &sourceError{t.line, t.col, fmt.Errorf(format, a...)}
warning := sourceError{t.line, t.col, fmt.Errorf(format, a...)}
ops.Warnings = append(ops.Warnings, warning)
}

Expand Down
25 changes: 17 additions & 8 deletions data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3604,10 +3604,13 @@ func TestReportMultipleErrors(t *testing.T) {
{Line: 1, Err: errors.New("error 1")},
{Err: errors.New("error 2")},
{Line: 3, Err: errors.New("error 3")},
{Line: 4, Column: 1, Err: errors.New("error 4")},
},
Warnings: []error{
errors.New("warning 1"),
errors.New("warning 2"),
Warnings: []sourceError{
{Line: 5, Err: errors.New("warning 1")},
{Err: errors.New("warning 2")},
{Line: 7, Err: errors.New("warning 3")},
{Line: 8, Column: 1, Err: errors.New("warning 4")},
},
}

Expand All @@ -3616,9 +3619,12 @@ func TestReportMultipleErrors(t *testing.T) {
ops.ReportMultipleErrors("test.txt", &b)
expected := `test.txt: 1: error 1
test.txt: 0: error 2
test.txt: 3: error 3
test.txt: warning 1
test.txt: warning 2
test.txt: 3: error 4
test.txt: 4:1: error 3
jasonpaulos marked this conversation as resolved.
Show resolved Hide resolved
test.txt: 5: warning 1
test.txt: 0: warning 2
test.txt: 7: warning 3
test.txt: 8:1: warning 4
`
require.Equal(t, expected, b.String())

Expand All @@ -3628,8 +3634,11 @@ test.txt: warning 2
expected = `1: error 1
0: error 2
3: error 3
warning 1
warning 2
4:1: error 4
5: warning 1
0: warning 2
7: warning 3
8:1: warning 4
`
require.Equal(t, expected, b.String())

Expand Down