@@ -4254,20 +4254,74 @@ let compareILVersions (a1,a2,a3,a4) ((b1,b2,b3,b4) : ILVersionInfo) =
4254
4254
if c <> 0 then c else
4255
4255
0
4256
4256
4257
+ let qunscope_scoref scoref_old =
4258
+ match scoref_ old with
4259
+ | ILScopeRef.Local -> None
4260
+ | _ -> Some ILScopeRef.Local
4261
+
4262
+ let qunscope_tref ( x : ILTypeRef ) =
4263
+ match qunscope_ scoref x.Scope with
4264
+ | None -> None
4265
+ | Some s -> Some ( ILTypeRef.Create( s, x.Enclosing, x.Name))
4266
+
4267
+ let unscopeILScopeRef y = match qunscope_ scoref y with Some x -> x | None -> y
4268
+ let unscopeILTypeRef y = match qunscope_ tref y with Some x -> x | None -> y
4269
+
4270
+ let rec unscopeILTypeSpecQuick ( tspec : ILTypeSpec ) =
4271
+ let tref = tspec.TypeRef
4272
+ let tinst = tspec.GenericArgs
4273
+ let qtref = qunscope_ tref tref
4274
+ if ILList.isEmpty tinst && isNone qtref then
4275
+ None (* avoid reallocation in the common case *)
4276
+ else
4277
+ match qtref with
4278
+ | None -> Some ( ILTypeSpec.Create ( tref, unscopeILTypes tinst))
4279
+ | Some tref -> Some ( ILTypeSpec.Create ( tref, unscopeILTypes tinst))
4280
+
4281
+ and unscopeILTypeSpec x y =
4282
+ match rescopeILTypeSpecQuick x y with
4283
+ | Some x -> x
4284
+ | None -> y
4285
+
4286
+ and unscopeILType typ =
4287
+ match typ with
4288
+ | ILType.Ptr t -> ILType.Ptr ( unscopeILType t)
4289
+ | ILType.FunctionPointer t -> ILType.FunctionPointer ( unscopeILCallSig t)
4290
+ | ILType.Byref t -> ILType.Byref ( unscopeILType t)
4291
+ | ILType.Boxed cr ->
4292
+ match unscopeILTypeSpecQuick cr with
4293
+ | Some res -> mkILBoxedType res
4294
+ | None -> typ // avoid reallocation in the common case
4295
+ | ILType.Array ( s, ty) -> ILType.Array ( s, unscopeILType ty)
4296
+ | ILType.Value cr ->
4297
+ match unscopeILTypeSpecQuick cr with
4298
+ | Some res -> ILType.Value res
4299
+ | None -> typ // avoid reallocation in the common case
4300
+ | ILType.Modified( b, tref, ty) -> ILType.Modified( b, unscopeILTypeRef tref, unscopeILType ty)
4301
+ | x -> x
4302
+
4303
+ and unscopeILTypes i =
4304
+ if ILList.isEmpty i then i
4305
+ else ILList.map unscopeILType i
4306
+
4307
+ and unscopeILCallSig csig =
4308
+ mkILCallSigRaw ( csig.CallingConv, unscopeILTypes csig.ArgTypes, unscopeILType csig.ReturnType)
4257
4309
4258
4310
let resolveILMethodRefWithRescope r td ( mref : ILMethodRef ) =
4259
4311
let args = mref.ArgTypes
4260
4312
let nargs = args.Length
4261
4313
let nm = mref.Name
4262
4314
let possibles = td.Methods.FindByNameAndArity ( nm, nargs)
4263
4315
if isNil possibles then failwith ( " no method named " + nm+ " found in type " + td.Name);
4316
+ let argTypes = mref.ArgTypes |> List.map r
4317
+ let retType : ILType = r mref.ReturnType
4264
4318
match
4265
4319
possibles |> List.filter ( fun md ->
4266
4320
mref.CallingConv = md.CallingConv &&
4267
4321
// REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
4268
- ( md.Parameters, mref.ArgTypes ) ||> ILList.lengthsEqAndForall2 ( fun p1 p2 -> r p1.Type = p2) &&
4322
+ ( md.Parameters, argTypes ) ||> ILList.lengthsEqAndForall2 ( fun p1 p2 -> r p1.Type = p2) &&
4269
4323
// REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
4270
- r md.Return.Type = mref.ReturnType ) with
4324
+ r md.Return.Type = retType ) with
4271
4325
| [] -> failwith ( " no method named " + nm+ " with appropriate argument types found in type " + td.Name)
4272
4326
| [ mdef] -> mdef
4273
4327
| _ -> failwith ( " multiple methods named " + nm+ " appear with identical argument types in type " + td.Name)
0 commit comments