mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
explicitly catch attempt to decode into a value - must be a pointer to see the result.
R=rsc https://golang.org/cl/163070
This commit is contained in:
parent
f9810f1b12
commit
ff3ea68e52
2 changed files with 20 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"io";
|
||||
"os";
|
||||
"reflect";
|
||||
"strings";
|
||||
"testing";
|
||||
)
|
||||
|
||||
|
|
@ -195,7 +196,6 @@ func TestPtrTypeToType(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTypeToPtrPtrPtrPtrType(t *testing.T) {
|
||||
// Encode a *T, decode a T
|
||||
type Type2 struct {
|
||||
a ****float;
|
||||
}
|
||||
|
|
@ -215,7 +215,6 @@ func TestTypeToPtrPtrPtrPtrType(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSlice(t *testing.T) {
|
||||
// Encode a *T, decode a T
|
||||
type Type3 struct {
|
||||
a []string;
|
||||
}
|
||||
|
|
@ -225,3 +224,15 @@ func TestSlice(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValueError(t *testing.T) {
|
||||
// Encode a *T, decode a T
|
||||
type Type4 struct {
|
||||
a int;
|
||||
}
|
||||
t4p := Type4{3}; // note: not a pointer, unlike the other tests.
|
||||
var t4 Type4;
|
||||
if err := encAndDec(t4, t4p); err == nil || strings.Index(err.String(), "pointer") <= 0 {
|
||||
t.Error("expected error; got none or got wrong one")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue