Skip to content

Commit e314fa7

Browse files
committed
Allow nil pointer dereference error instead of hidden it
1 parent e06c92d commit e314fa7

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

.golangci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ run:
1717
# If false (default) - golangci-lint acquires file lock on start.
1818
allow-parallel-runners: true
1919

20-
skip-dirs:
20+
exclude-dirs:
2121
- test/testdata_etc # test files
2222
- internal/cache # extracted from Go code
2323
- internal/renameio # extracted from Go code
@@ -31,7 +31,7 @@ run:
3131
# output configuration options
3232
output:
3333
# Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
34-
Format: colored-line-number
34+
Formats: colored-line-number
3535
# Multiple can be specified by separating them by comma, output can be provided
3636
# for each of them by separating format name and path by colon symbol.
3737
# Output path can be either `stdout`, `stderr` or path to the file to write to.
@@ -153,7 +153,7 @@ linters-settings:
153153
govet:
154154
disable:
155155
- sigchanyzer
156-
check-shadowing: true
156+
shadow: true
157157
settings:
158158
printf:
159159
funcs:

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require github.com/stretchr/testify v1.8.4
66

77
require (
88
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/google/uuid v1.6.0 // indirect
910
github.com/pmezard/go-difflib v1.0.0 // indirect
1011
gopkg.in/yaml.v3 v3.0.1 // indirect
1112
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
35
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
46
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
57
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=

of.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,13 @@ func (n *Of[T]) GetValue() *T {
3131

3232
// SetValue implements the setter.
3333
func (n *Of[T]) SetValue(b T) {
34-
if n == nil {
35-
n = new(Of[T])
36-
n.SetValue(b)
37-
38-
return
39-
}
40-
4134
n.Val = &b
4235
}
4336

4437
// SetValueP implements the setter by pointer.
4538
// If ref is not nil, calls SetValue(*ref)
4639
// If ref is nil, calls SetNull()
4740
func (n *Of[T]) SetValueP(ref *T) {
48-
if n == nil {
49-
n = new(Of[T])
50-
}
51-
5241
if ref != nil {
5342
n.SetValue(*ref)
5443
} else {
@@ -59,7 +48,7 @@ func (n *Of[T]) SetValueP(ref *T) {
5948
// SetNull set to null.
6049
func (n *Of[T]) SetNull() {
6150
if n == nil {
62-
panic("calling SetNull on nil receiver")
51+
return
6352
}
6453

6554
n.Val = nil

0 commit comments

Comments
 (0)