Debian Codegraph @

go/analysis/passes/unmarshal/testdata/src/a/a.go

raw symbols SCIP
1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // This file contains tests for the unmarshal checker.
6
7 package testdata
8
9 import (
10 "encoding/asn1"
11 "encoding/gob"
12 "encoding/json"
13 "encoding/xml"
14 "io"
15 )
16
17 func _() {
18 type t struct {
19 a int
20 }
21 var v t
22 var r io.Reader
23
24 json.Unmarshal([]byte{}, v) // want "call of Unmarshal passes non-pointer as second argument"
25 json.Unmarshal([]byte{}, &v)
26 json.NewDecoder(r).Decode(v) // want "call of Decode passes non-pointer"
27 json.NewDecoder(r).Decode(&v)
28 gob.NewDecoder(r).Decode(v) // want "call of Decode passes non-pointer"
29 gob.NewDecoder(r).Decode(&v)
30 xml.Unmarshal([]byte{}, v) // want "call of Unmarshal passes non-pointer as second argument"
31 xml.Unmarshal([]byte{}, &v)
32 xml.NewDecoder(r).Decode(v) // want "call of Decode passes non-pointer"
33 xml.NewDecoder(r).Decode(&v)
34 asn1.Unmarshal([]byte{}, v) // want "call of Unmarshal passes non-pointer as second argument"
35 asn1.Unmarshal([]byte{}, &v)
36
37 var p *t
38 json.Unmarshal([]byte{}, p)
39 json.Unmarshal([]byte{}, *p) // want "call of Unmarshal passes non-pointer as second argument"
40 json.NewDecoder(r).Decode(p)
41 json.NewDecoder(r).Decode(*p) // want "call of Decode passes non-pointer"
42 gob.NewDecoder(r).Decode(p)
43 gob.NewDecoder(r).Decode(*p) // want "call of Decode passes non-pointer"
44 xml.Unmarshal([]byte{}, p)
45 xml.Unmarshal([]byte{}, *p) // want "call of Unmarshal passes non-pointer as second argument"
46 xml.NewDecoder(r).Decode(p)
47 xml.NewDecoder(r).Decode(*p) // want "call of Decode passes non-pointer"
48 asn1.Unmarshal([]byte{}, p)
49 asn1.Unmarshal([]byte{}, *p) // want "call of Unmarshal passes non-pointer as second argument"
50
51 var i interface{}
52 json.Unmarshal([]byte{}, i)
53 json.NewDecoder(r).Decode(i)
54
55 json.Unmarshal([]byte{}, nil) // want "call of Unmarshal passes non-pointer as second argument"
56 json.Unmarshal([]byte{}, []t{}) // want "call of Unmarshal passes non-pointer as second argument"
57 json.Unmarshal([]byte{}, map[string]int{}) // want "call of Unmarshal passes non-pointer as second argument"
58 json.NewDecoder(r).Decode(nil) // want "call of Decode passes non-pointer"
59 json.NewDecoder(r).Decode([]t{}) // want "call of Decode passes non-pointer"
60 json.NewDecoder(r).Decode(map[string]int{}) // want "call of Decode passes non-pointer"
61
62 json.Unmarshal(func() ([]byte, interface{}) { return []byte{}, v }())
63 }