reflect: uncomment another test and fix RO logic issues it uncovered
Этот коммит содержится в:
родитель
e0bf376068
коммит
b39a982067
2 изменённых файлов: 16 добавлений и 7 удалений
|
@ -7659,8 +7659,6 @@ func TestAliasNames(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
func TestIssue22031(t *testing.T) {
|
func TestIssue22031(t *testing.T) {
|
||||||
type s []struct{ C int }
|
type s []struct{ C int }
|
||||||
|
|
||||||
|
@ -7679,6 +7677,8 @@ func TestIssue22031(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
type NonExportedFirst int
|
type NonExportedFirst int
|
||||||
|
|
||||||
func (i NonExportedFirst) ΦExported() {}
|
func (i NonExportedFirst) ΦExported() {}
|
||||||
|
|
|
@ -20,6 +20,13 @@ const (
|
||||||
valueFlagRO = valueFlagEmbedRO | valueFlagStickyRO
|
valueFlagRO = valueFlagEmbedRO | valueFlagStickyRO
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (v valueFlags) ro() valueFlags {
|
||||||
|
if v&valueFlagRO != 0 {
|
||||||
|
return valueFlagStickyRO
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
type Value struct {
|
type Value struct {
|
||||||
typecode *rawType
|
typecode *rawType
|
||||||
value unsafe.Pointer
|
value unsafe.Pointer
|
||||||
|
@ -269,11 +276,11 @@ func (v Value) Addr() Value {
|
||||||
if !v.CanAddr() {
|
if !v.CanAddr() {
|
||||||
panic("reflect.Value.Addr of unaddressable value")
|
panic("reflect.Value.Addr of unaddressable value")
|
||||||
}
|
}
|
||||||
|
flags := (v.flags & (valueFlagExported)) | v.flags.ro()
|
||||||
return Value{
|
return Value{
|
||||||
typecode: pointerTo(v.typecode),
|
typecode: pointerTo(v.typecode),
|
||||||
value: v.value,
|
value: v.value,
|
||||||
flags: v.flags ^ valueFlagIndirect,
|
flags: flags,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,10 +666,12 @@ func (v Value) Elem() Value {
|
||||||
if ptr == nil {
|
if ptr == nil {
|
||||||
return Value{}
|
return Value{}
|
||||||
}
|
}
|
||||||
|
// Don't copy RO flags
|
||||||
|
flags := (v.flags & (valueFlagIndirect | valueFlagExported)) | valueFlagIndirect
|
||||||
return Value{
|
return Value{
|
||||||
typecode: v.typecode.elem(),
|
typecode: v.typecode.elem(),
|
||||||
value: ptr,
|
value: ptr,
|
||||||
flags: v.flags | valueFlagIndirect,
|
flags: flags,
|
||||||
}
|
}
|
||||||
case Interface:
|
case Interface:
|
||||||
typecode, value := decomposeInterface(*(*interface{})(v.value))
|
typecode, value := decomposeInterface(*(*interface{})(v.value))
|
||||||
|
@ -685,7 +694,6 @@ func (v Value) Field(i int) Value {
|
||||||
|
|
||||||
// Copy flags but clear EmbedRO; we're not an embedded field anymore
|
// Copy flags but clear EmbedRO; we're not an embedded field anymore
|
||||||
flags := v.flags & ^valueFlagEmbedRO
|
flags := v.flags & ^valueFlagEmbedRO
|
||||||
|
|
||||||
if structField.PkgPath != "" {
|
if structField.PkgPath != "" {
|
||||||
// No PkgPath => not exported.
|
// No PkgPath => not exported.
|
||||||
// Clear exported flag even if the parent was exported.
|
// Clear exported flag even if the parent was exported.
|
||||||
|
@ -764,9 +772,10 @@ func (v Value) Index(i int) Value {
|
||||||
if uint(i) >= uint(slice.len) {
|
if uint(i) >= uint(slice.len) {
|
||||||
panic("reflect: slice index out of range")
|
panic("reflect: slice index out of range")
|
||||||
}
|
}
|
||||||
|
flags := (v.flags & (valueFlagExported | valueFlagIndirect)) | valueFlagIndirect | v.flags.ro()
|
||||||
elem := Value{
|
elem := Value{
|
||||||
typecode: v.typecode.elem(),
|
typecode: v.typecode.elem(),
|
||||||
flags: v.flags | valueFlagIndirect,
|
flags: flags,
|
||||||
}
|
}
|
||||||
elem.value = unsafe.Add(slice.data, elem.typecode.Size()*uintptr(i)) // pointer to new value
|
elem.value = unsafe.Add(slice.data, elem.typecode.Size()*uintptr(i)) // pointer to new value
|
||||||
return elem
|
return elem
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче