Skip to content

Commit

Permalink
Allow nil pointer dereference error instead of hidden it
Browse files Browse the repository at this point in the history
  • Loading branch information
pivaldi committed Apr 30, 2024
1 parent e06c92d commit e314fa7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -153,7 +153,7 @@ linters-settings:
govet:
disable:
- sigchanyzer
check-shadowing: true
shadow: true
settings:
printf:
funcs:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
13 changes: 1 addition & 12 deletions of.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,13 @@ 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
}

// SetValueP implements the setter by pointer.
// 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 {
Expand All @@ -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
Expand Down

0 comments on commit e314fa7

Please sign in to comment.