From e314fa745702693c348c84c00b7c88683d9b7cfa Mon Sep 17 00:00:00 2001 From: pi Date: Tue, 30 Apr 2024 18:37:25 +0200 Subject: [PATCH] Allow nil pointer dereference error instead of hidden it --- .golangci.yml | 6 +++--- go.mod | 1 + go.sum | 2 ++ of.go | 13 +------------ 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 261f0dc..5b59338 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,7 +17,7 @@ run: # If false (default) - golangci-lint acquires file lock on start. allow-parallel-runners: true - skip-dirs: + exclude-dirs: - test/testdata_etc # test files - internal/cache # extracted from Go code - internal/renameio # extracted from Go code @@ -31,7 +31,7 @@ run: # output configuration options output: # Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity - Format: colored-line-number + Formats: colored-line-number # Multiple can be specified by separating them by comma, output can be provided # for each of them by separating format name and path by colon symbol. # Output path can be either `stdout`, `stderr` or path to the file to write to. @@ -153,7 +153,7 @@ linters-settings: govet: disable: - sigchanyzer - check-shadowing: true + shadow: true settings: printf: funcs: diff --git a/go.mod b/go.mod index 1667649..ce08dcc 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require github.com/stretchr/testify v1.8.4 require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index fa4b6e6..fcca6d1 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= diff --git a/of.go b/of.go index da82229..0278b49 100644 --- a/of.go +++ b/of.go @@ -31,13 +31,6 @@ func (n *Of[T]) GetValue() *T { // SetValue implements the setter. func (n *Of[T]) SetValue(b T) { - if n == nil { - n = new(Of[T]) - n.SetValue(b) - - return - } - n.Val = &b } @@ -45,10 +38,6 @@ func (n *Of[T]) SetValue(b T) { // If ref is not nil, calls SetValue(*ref) // If ref is nil, calls SetNull() func (n *Of[T]) SetValueP(ref *T) { - if n == nil { - n = new(Of[T]) - } - if ref != nil { n.SetValue(*ref) } else { @@ -59,7 +48,7 @@ func (n *Of[T]) SetValueP(ref *T) { // SetNull set to null. func (n *Of[T]) SetNull() { if n == nil { - panic("calling SetNull on nil receiver") + return } n.Val = nil