mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
parent
85f8a604a5
commit
15963edb57
5 changed files with 0 additions and 76 deletions
28
test/testdata/nilassign.go
vendored
28
test/testdata/nilassign.go
vendored
|
@ -1,28 +0,0 @@
|
|||
//args: -Enilassign
|
||||
package testdata
|
||||
|
||||
var num = 1
|
||||
|
||||
func pvar() {
|
||||
var ii *int
|
||||
*ii = 1 // ERROR "this assignment occurs invalid memory address or nil pointer dereference"
|
||||
|
||||
var i *int
|
||||
i = &num // OK
|
||||
_ = i // OK
|
||||
}
|
||||
|
||||
func pstruct() {
|
||||
n := new(Node)
|
||||
|
||||
*n.PVal = 1 // ERROR "this assignment occurs invalid memory address or nil pointer dereference"
|
||||
*n.ChildNode.PVal = 1 // ERROR "this assignment occurs invalid memory address or nil pointer dereference"
|
||||
|
||||
n.ChildNode = &Node{PVal: &num} // OK
|
||||
n.PVal = &num // OK
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
PVal *int
|
||||
ChildNode *Node
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue