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
7package testdata
8
9import (
10	"encoding/gob"
11	"encoding/json"
12	"encoding/xml"
13	"io"
14)
15
16func _() {
17	type t struct {
18		a int
19	}
20	var v t
21	var r io.Reader
22
23	json.Unmarshal([]byte{}, v) // want "call of Unmarshal passes non-pointer as second argument"
24	json.Unmarshal([]byte{}, &v)
25	json.NewDecoder(r).Decode(v) // want "call of Decode passes non-pointer"
26	json.NewDecoder(r).Decode(&v)
27	gob.NewDecoder(r).Decode(v) // want "call of Decode passes non-pointer"
28	gob.NewDecoder(r).Decode(&v)
29	xml.Unmarshal([]byte{}, v) // want "call of Unmarshal passes non-pointer as second argument"
30	xml.Unmarshal([]byte{}, &v)
31	xml.NewDecoder(r).Decode(v) // want "call of Decode passes non-pointer"
32	xml.NewDecoder(r).Decode(&v)
33
34	var p *t
35	json.Unmarshal([]byte{}, p)
36	json.Unmarshal([]byte{}, *p) // want "call of Unmarshal passes non-pointer as second argument"
37	json.NewDecoder(r).Decode(p)
38	json.NewDecoder(r).Decode(*p) // want "call of Decode passes non-pointer"
39	gob.NewDecoder(r).Decode(p)
40	gob.NewDecoder(r).Decode(*p) // want "call of Decode passes non-pointer"
41	xml.Unmarshal([]byte{}, p)
42	xml.Unmarshal([]byte{}, *p) // want "call of Unmarshal passes non-pointer as second argument"
43	xml.NewDecoder(r).Decode(p)
44	xml.NewDecoder(r).Decode(*p) // want "call of Decode passes non-pointer"
45
46	var i interface{}
47	json.Unmarshal([]byte{}, i)
48	json.NewDecoder(r).Decode(i)
49
50	json.Unmarshal([]byte{}, nil)               // want "call of Unmarshal passes non-pointer as second argument"
51	json.Unmarshal([]byte{}, []t{})             // want "call of Unmarshal passes non-pointer as second argument"
52	json.Unmarshal([]byte{}, map[string]int{})  // want "call of Unmarshal passes non-pointer as second argument"
53	json.NewDecoder(r).Decode(nil)              // want "call of Decode passes non-pointer"
54	json.NewDecoder(r).Decode([]t{})            // want "call of Decode passes non-pointer"
55	json.NewDecoder(r).Decode(map[string]int{}) // want "call of Decode passes non-pointer"
56
57	json.Unmarshal(func() ([]byte, interface{}) { return []byte{}, v }())
58}
59