Skip to content

Commit b4b9a3e

Browse files
committed
Implement marshaling for generic struct fields (case 1106422)
1 parent 081f213 commit b4b9a3e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mono/metadata/marshal.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,12 +2281,20 @@ emit_struct_conv_full (MonoMethodBuilder *mb, MonoClass *klass, gboolean to_obje
22812281
mono_mb_emit_byte (mb, mono_type_to_stind (ftype));
22822282
}
22832283
break;
2284+
case MONO_TYPE_GENERICINST:
2285+
if (!mono_type_generic_inst_is_valuetype (ftype)) {
2286+
char *msg = g_strdup_printf ("Generic type %s cannot be marshaled as field in a struct.",
2287+
mono_type_full_name (ftype));
2288+
mono_mb_emit_exception_marshal_directive (mb, msg);
2289+
break;
2290+
}
2291+
/* fall through */
22842292
case MONO_TYPE_VALUETYPE: {
22852293
int src_var, dst_var;
22862294
MonoType *etype;
22872295
int len;
22882296

2289-
if (ftype->data.klass->enumtype) {
2297+
if (t == MONO_TYPE_VALUETYPE && ftype->data.klass->enumtype) {
22902298
ftype = mono_class_enum_basetype (ftype->data.klass);
22912299
goto handle_enum;
22922300
}
@@ -2304,7 +2312,7 @@ emit_struct_conv_full (MonoMethodBuilder *mb, MonoClass *klass, gboolean to_obje
23042312
if (get_fixed_buffer_attr (info->fields [i].field, &etype, &len)) {
23052313
emit_fixed_buf_conv (mb, ftype, etype, len, to_object, &usize);
23062314
} else {
2307-
emit_struct_conv (mb, ftype->data.klass, to_object);
2315+
emit_struct_conv (mb, mono_class_from_mono_type (ftype), to_object);
23082316
}
23092317

23102318
/* restore the old src pointer */

0 commit comments

Comments
 (0)