"func sys.ifaceI2T (sigt *uint8, iface any) (ret any)\n"
"func sys.ifaceI2T2 (sigt *uint8, iface any) (ret any, ok bool)\n"
"func sys.ifaceI2I (sigi *uint8, iface any) (ret any)\n"
+ "func sys.ifaceI2Ix (sigi *uint8, iface any) (ret any)\n"
"func sys.ifaceI2I2 (sigi *uint8, iface any) (ret any, ok bool)\n"
"func sys.ifaceeq (i1 any, i2 any) (ret bool)\n"
"func sys.efaceeq (i1 any, i2 any) (ret bool)\n"
func ifaceI2T(sigt *byte, iface any) (ret any);
func ifaceI2T2(sigt *byte, iface any) (ret any, ok bool);
func ifaceI2I(sigi *byte, iface any) (ret any);
+func ifaceI2Ix(sigi *byte, iface any) (ret any);
func ifaceI2I2(sigi *byte, iface any) (ret any, ok bool);
func ifaceeq(i1 any, i2 any) (ret bool);
func efaceeq(i1 any, i2 any) (ret bool);
}
// ifaceI2I(sigi *byte, iface any) (ret any);
+// called only for implicit (no type assertion) conversions
void
sys·ifaceI2I(Sigi *si, Iface i, Iface ret)
{
im = i.type;
if(im == nil) {
-//TODO(rsc): fixme
// If incoming interface is uninitialized (zeroed)
// make the outgoing interface zeroed as well.
ret = niliface;
FLUSH(&ret);
}
+// ifaceI2Ix(sigi *byte, iface any) (ret any);
+// called only for explicit conversions (with type assertion).
+void
+sys·ifaceI2Ix(Sigi *si, Iface i, Iface ret)
+{
+ Itype *im;
+
+ im = i.type;
+ if(im == nil) {
+ // explicit conversions require non-nil interface value.
+ printf("interface is nil, not %s\n", si->name);
+ throw("interface conversion");
+ } else {
+ ret = i;
+ if(im->sigi != si)
+ ret.type = itype(si, im->sigt, 0);
+ }
+
+ FLUSH(&ret);
+}
+
// ifaceI2I2(sigi *byte, iface any) (ret any, ok bool);
void
sys·ifaceI2I2(Sigi *si, Iface i, Iface ret, bool ok)
Itype *im;
im = i.type;
- ok = true;
if(im == nil) {
-//TODO: fixme
- // If incoming interface is uninitialized (zeroed)
- // make the outgoing interface zeroed as well.
+ // If incoming interface is nil, the conversion fails.
ret = niliface;
+ ok = false;
} else {
ret = i;
+ ok = true;
if(im->sigi != si) {
ret.type = itype(si, im->sigt, 1);
if(ret.type == nil) {
}
// ifaceE2I(sigi *byte, iface any) (ret any);
+// Called only for explicit conversions (with type assertion).
void
sys·ifaceE2I(Sigi *si, Eface e, Iface ret)
{
t = e.type;
if(t == nil) {
-//TODO(rsc): fixme
- ret = niliface;
+ // explicit conversions require non-nil interface value.
+ printf("interface is nil, not %s\n", si->name);
+ throw("interface conversion");
} else {
ret.data = e.data;
ret.type = itype(si, t, 0);
t = e.type;
ok = true;
if(t == nil) {
-//TODO(rsc): fixme
+ // If incoming interface is nil, the conversion fails.
ret = niliface;
+ ok = false;
} else {
ret.data = e.data;
ret.type = itype(si, t, 1);