mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 16:33:40 +00:00
reflect: use TestConvert from all_test.go and make it pass
This PR removes convert_test.go which was a minimal version of this test.
This commit is contained in:
committed by
Damian Gryski
parent
3abe58448b
commit
1c0c26b8b7
@@ -47,12 +47,20 @@ func (v Value) isExported() bool {
|
||||
return v.flags&valueFlagExported != 0
|
||||
}
|
||||
|
||||
func (v Value) isRO() bool {
|
||||
func (v Value) IsRO() bool {
|
||||
return v.flags&(valueFlagRO) != 0
|
||||
}
|
||||
|
||||
func (v *Value) MakeRO(ro bool) {
|
||||
if ro {
|
||||
v.flags |= valueFlagRO
|
||||
} else {
|
||||
v.flags &^= valueFlagRO
|
||||
}
|
||||
}
|
||||
|
||||
func (v Value) checkRO() {
|
||||
if v.isRO() {
|
||||
if v.IsRO() {
|
||||
panic("reflect: value is not settable")
|
||||
}
|
||||
}
|
||||
@@ -297,7 +305,7 @@ func (v Value) IsValid() bool {
|
||||
}
|
||||
|
||||
func (v Value) CanInterface() bool {
|
||||
return v.isExported() && !v.isRO()
|
||||
return v.isExported() && !v.IsRO()
|
||||
}
|
||||
|
||||
func (v Value) CanAddr() bool {
|
||||
@@ -1532,6 +1540,12 @@ func convertOp(src Value, typ Type) (Value, bool) {
|
||||
return cvtStringRunes(src, rtype), true
|
||||
}
|
||||
}
|
||||
|
||||
case Pointer:
|
||||
rtype := typ.(*RawType)
|
||||
if rtype.Kind() == Pointer && !rtype.isNamed() {
|
||||
return cvtDirect(src, rtype), true
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(dgryski): Unimplemented:
|
||||
@@ -1576,6 +1590,14 @@ func cvtFloat(v Value, t *RawType) Value {
|
||||
return makeFloat(v.flags, v.Float(), t)
|
||||
}
|
||||
|
||||
func cvtDirect(v Value, t *RawType) Value {
|
||||
return Value{
|
||||
typecode: t,
|
||||
value: v.value,
|
||||
flags: v.flags,
|
||||
}
|
||||
}
|
||||
|
||||
func cvtComplex(v Value, t *RawType) Value {
|
||||
return makeComplex(v.flags, v.Complex(), t)
|
||||
}
|
||||
@@ -1697,7 +1719,7 @@ func cvtIntString(v Value, t *RawType) Value {
|
||||
return Value{
|
||||
typecode: t,
|
||||
value: unsafe.Pointer(&s),
|
||||
flags: v.flags | valueFlagRO,
|
||||
flags: v.flags,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1710,7 +1732,7 @@ func cvtUintString(v Value, t *RawType) Value {
|
||||
return Value{
|
||||
typecode: t,
|
||||
value: unsafe.Pointer(&s),
|
||||
flags: v.flags | valueFlagRO,
|
||||
flags: v.flags,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user