@@ -2355,6 +2355,8 @@ unsafe_accessor_target_type_forbidden (MonoType *target_type)
2355
2355
case MONO_TYPE_VOID :
2356
2356
case MONO_TYPE_PTR :
2357
2357
case MONO_TYPE_FNPTR :
2358
+ case MONO_TYPE_VAR :
2359
+ case MONO_TYPE_MVAR :
2358
2360
return TRUE;
2359
2361
default :
2360
2362
return FALSE;
@@ -2422,16 +2424,17 @@ emit_unsafe_accessor_ctor_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor_m
2422
2424
}
2423
2425
2424
2426
MonoType * target_type = sig -> ret ; // for constructors the return type is the target type
2425
- if (target_type == NULL || m_type_is_byref (target_type ) || unsafe_accessor_target_type_forbidden (target_type )) {
2426
- mono_mb_emit_exception_full (mb , "System" , "BadImageFormatException" , "Invalid usage of UnsafeAccessorAttribute." );
2427
- return ;
2428
- }
2429
-
2430
2427
MonoClass * target_class = mono_class_from_mono_type_internal (target_type );
2431
2428
2432
2429
ERROR_DECL (find_method_error );
2433
2430
if (accessor_method -> is_inflated ) {
2434
2431
sig = update_signature (accessor_method );
2432
+ target_type = sig -> ret ;
2433
+ }
2434
+
2435
+ if (target_type == NULL || m_type_is_byref (target_type ) || unsafe_accessor_target_type_forbidden (target_type )) {
2436
+ mono_mb_emit_exception_full (mb , "System" , "BadImageFormatException" , "Invalid usage of UnsafeAccessorAttribute." );
2437
+ return ;
2435
2438
}
2436
2439
2437
2440
MonoMethodSignature * member_sig = ctor_sig_from_accessor_sig (mb , sig , ctx );
@@ -2467,10 +2470,7 @@ emit_unsafe_accessor_method_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor
2467
2470
// We explicitly allow calling a constructor as if it was an instance method, but we need some hacks in a couple of places
2468
2471
gboolean ctor_as_method = !strcmp (member_name , ".ctor" );
2469
2472
2470
- if (sig -> param_count < 1 || sig -> params [0 ] == NULL || unsafe_accessor_target_type_forbidden (sig -> params [0 ])) {
2471
- mono_mb_emit_exception_full (mb , "System" , "BadImageFormatException" , "Invalid usage of UnsafeAccessorAttribute." );
2472
- return ;
2473
- }
2473
+
2474
2474
2475
2475
MonoType * target_type = sig -> params [0 ];
2476
2476
gboolean hasthis = kind == MONO_UNSAFE_ACCESSOR_METHOD ;
@@ -2484,6 +2484,12 @@ emit_unsafe_accessor_method_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor
2484
2484
ERROR_DECL (find_method_error );
2485
2485
if (accessor_method -> is_inflated ) {
2486
2486
sig = update_signature (accessor_method );
2487
+ target_type = sig -> params [0 ];
2488
+ }
2489
+
2490
+ if (sig -> param_count < 1 || target_type == NULL || unsafe_accessor_target_type_forbidden (target_type )) {
2491
+ mono_mb_emit_exception_full (mb , "System" , "BadImageFormatException" , "Invalid usage of UnsafeAccessorAttribute." );
2492
+ return ;
2487
2493
}
2488
2494
2489
2495
MonoMethodSignature * member_sig = method_sig_from_accessor_sig (mb , hasthis , sig , ctx );
0 commit comments