Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions errchkjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func (e *errchkjson) run(pass *analysis.Pass) (interface{}, error) {
return true
}

// if the error is returned, it is the caller's responsibility to check
// the return value.
if _, ok := n.(*ast.ReturnStmt); ok {
return false
}

ce, ok := n.(*ast.CallExpr)
if ok {
fn, _ := typeutil.Callee(pass.TypesInfo, ce).(*types.Func)
Expand Down
9 changes: 9 additions & 0 deletions testdata/src/nosafe/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,12 @@ func NotJSONMarshal() {
f := func() bool { return false }
_ = f()
}

// Issue 5
type T struct {
s string
}

func (t T) MarshalJSON() ([]byte, error) {
return json.Marshal(t.s) // not an error because it is the caller's responsibility to check the error
}
9 changes: 9 additions & 0 deletions testdata/src/standard/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,12 @@ func NotJSONMarshal() {
f := func() bool { return false }
_ = f()
}

// Issue 5
type T struct {
f64 float64
}

func (t T) MarshalJSON() ([]byte, error) {
return json.Marshal(t.f64) // not an error because it is the caller's responsibility to check the error
}