@@ -517,65 +517,118 @@ let IsMethInfoPlainCSharpStyleExtensionMember g m isEnclExtTy (minfo: MethInfo)
517517/// Get the info for all the .NET-style extension members listed as static members in the type.
518518let private GetCSharpStyleIndexedExtensionMembersForTyconRef ( amap : Import.ImportMap ) m ( tcrefOfStaticClass : TyconRef ) =
519519 let g = amap.g
520- let ty = generalizedTyconRef g tcrefOfStaticClass
520+
521+ if g.langVersion.SupportsFeature( LanguageFeature.CSharpExtensionAttributeNotRequired) then
522+ let ty = generalizedTyconRef g tcrefOfStaticClass
523+
524+ let minfos =
525+ GetImmediateIntrinsicMethInfosOfType ( None, AccessorDomain.AccessibleFromSomeFSharpCode) g amap m ty
526+ |> List.filter ( IsMethInfoPlainCSharpStyleExtensionMember g m true )
521527
522- let minfos =
523- GetImmediateIntrinsicMethInfosOfType ( None, AccessorDomain.AccessibleFromSomeFSharpCode) g amap m ty
524- |> List.filter ( IsMethInfoPlainCSharpStyleExtensionMember g m true )
525-
526- if IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass || not minfos.IsEmpty then
527- let pri = NextExtensionMethodPriority()
528-
529- [ for minfo in minfos do
530- let ilExtMem = ILExtMem ( tcrefOfStaticClass, minfo, pri)
531-
532- // The results are indexed by the TyconRef of the first 'this' argument, if any.
533- // So we need to go and crack the type of the 'this' argument.
534- //
535- // This is convoluted because we only need the ILTypeRef of the first argument, and we don't
536- // want to read any other metadata as it can trigger missing-assembly errors. It turns out ImportILTypeRef
537- // is less eager in reading metadata than GetParamTypes.
538- //
539- // We don't use the index for the IL extension method for tuple of F# function types (e.g. if extension
540- // methods for tuple occur in C# code)
541- let thisTyconRef =
542- try
543- let rs =
544- match metadataOfTycon tcrefOfStaticClass.Deref, minfo with
545- | ILTypeMetadata ( TILObjectReprData( scoref, _, _)), ILMeth(_, ILMethInfo(_, _, _, ilMethod, _), _) ->
546- match ilMethod.ParameterTypes with
547- | firstTy :: _ ->
548- match firstTy with
549- | ILType.Boxed tspec | ILType.Value tspec ->
550- let tref = ( tspec |> rescopeILTypeSpec scoref) .TypeRef
551- if Import.CanImportILTypeRef amap m tref then
552- let tcref = tref |> Import.ImportILTypeRef amap m
553- if isCompiledTupleTyconRef g tcref || tyconRefEq g tcref g.fastFunc_ tcr then None
554- else Some tcref
555- else None
528+ if IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass || not minfos.IsEmpty then
529+ let pri = NextExtensionMethodPriority()
530+
531+ [ for minfo in minfos do
532+ let ilExtMem = ILExtMem ( tcrefOfStaticClass, minfo, pri)
533+
534+ // The results are indexed by the TyconRef of the first 'this' argument, if any.
535+ // So we need to go and crack the type of the 'this' argument.
536+ //
537+ // This is convoluted because we only need the ILTypeRef of the first argument, and we don't
538+ // want to read any other metadata as it can trigger missing-assembly errors. It turns out ImportILTypeRef
539+ // is less eager in reading metadata than GetParamTypes.
540+ //
541+ // We don't use the index for the IL extension method for tuple of F# function types (e.g. if extension
542+ // methods for tuple occur in C# code)
543+ let thisTyconRef =
544+ try
545+ let rs =
546+ match metadataOfTycon tcrefOfStaticClass.Deref, minfo with
547+ | ILTypeMetadata ( TILObjectReprData( scoref, _, _)), ILMeth(_, ILMethInfo(_, _, _, ilMethod, _), _) ->
548+ match ilMethod.ParameterTypes with
549+ | firstTy :: _ ->
550+ match firstTy with
551+ | ILType.Boxed tspec | ILType.Value tspec ->
552+ let tref = ( tspec |> rescopeILTypeSpec scoref) .TypeRef
553+ if Import.CanImportILTypeRef amap m tref then
554+ let tcref = tref |> Import.ImportILTypeRef amap m
555+ if isCompiledTupleTyconRef g tcref || tyconRefEq g tcref g.fastFunc_ tcr then None
556+ else Some tcref
557+ else None
558+ | _ -> None
559+ | _ -> None
560+ | _ ->
561+ // The results are indexed by the TyconRef of the first 'this' argument, if any.
562+ // So we need to go and crack the type of the 'this' argument.
563+ let thisTy = minfo.GetParamTypes( amap, m, generalizeTypars minfo.FormalMethodTypars) .Head.Head
564+ match thisTy with
565+ | AppTy g ( tcrefOfTypeExtended, _) when not ( isByrefTy g thisTy) -> Some tcrefOfTypeExtended
556566 | _ -> None
557- | _ -> None
558- | _ ->
559- // The results are indexed by the TyconRef of the first 'this' argument, if any.
560- // So we need to go and crack the type of the 'this' argument.
561- let thisTy = minfo.GetParamTypes( amap, m, generalizeTypars minfo.FormalMethodTypars) .Head.Head
562- match thisTy with
563- | AppTy g ( tcrefOfTypeExtended, _) when not ( isByrefTy g thisTy) -> Some tcrefOfTypeExtended
564- | _ -> None
565-
566- Some rs
567-
568- with e -> // Import of the ILType may fail, if so report the error and skip on
569- errorRecovery e m
570- None
571-
572- match thisTyconRef with
573- | None -> ()
574- | Some ( Some tcref) -> yield Choice1Of2( tcref, ilExtMem)
575- | Some None -> yield Choice2Of2 ilExtMem ]
576- else
577- []
578567
568+ Some rs
569+
570+ with e -> // Import of the ILType may fail, if so report the error and skip on
571+ errorRecovery e m
572+ None
573+
574+ match thisTyconRef with
575+ | None -> ()
576+ | Some ( Some tcref) -> yield Choice1Of2( tcref, ilExtMem)
577+ | Some None -> yield Choice2Of2 ilExtMem ]
578+ else
579+ []
580+ else
581+ if IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass then
582+ let pri = NextExtensionMethodPriority()
583+ let ty = generalizedTyconRef g tcrefOfStaticClass
584+ let minfos = GetImmediateIntrinsicMethInfosOfType ( None, AccessorDomain.AccessibleFromSomeFSharpCode) g amap m ty
585+
586+ [ for minfo in minfos do
587+ if IsMethInfoPlainCSharpStyleExtensionMember g m true minfo then
588+ let ilExtMem = ILExtMem ( tcrefOfStaticClass, minfo, pri)
589+ // The results are indexed by the TyconRef of the first 'this' argument, if any.
590+ // So we need to go and crack the type of the 'this' argument.
591+ //
592+ // This is convoluted because we only need the ILTypeRef of the first argument, and we don't
593+ // want to read any other metadata as it can trigger missing-assembly errors. It turns out ImportILTypeRef
594+ // is less eager in reading metadata than GetParamTypes.
595+ //
596+ // We don't use the index for the IL extension method for tuple of F# function types (e.g. if extension
597+ // methods for tuple occur in C# code)
598+ let thisTyconRef =
599+ try
600+ let rs =
601+ match metadataOfTycon tcrefOfStaticClass.Deref, minfo with
602+ | ILTypeMetadata ( TILObjectReprData( scoref, _, _)), ILMeth(_, ILMethInfo(_, _, _, ilMethod, _), _) ->
603+ match ilMethod.ParameterTypes with
604+ | firstTy :: _ ->
605+ match firstTy with
606+ | ILType.Boxed tspec | ILType.Value tspec ->
607+ let tref = ( tspec |> rescopeILTypeSpec scoref) .TypeRef
608+ if Import.CanImportILTypeRef amap m tref then
609+ let tcref = tref |> Import.ImportILTypeRef amap m
610+ if isCompiledTupleTyconRef g tcref || tyconRefEq g tcref g.fastFunc_ tcr then None
611+ else Some tcref
612+ else None
613+ | _ -> None
614+ | _ -> None
615+ | _ ->
616+ // The results are indexed by the TyconRef of the first 'this' argument, if any.
617+ // So we need to go and crack the type of the 'this' argument.
618+ let thisTy = minfo.GetParamTypes( amap, m, generalizeTypars minfo.FormalMethodTypars) .Head.Head
619+ match thisTy with
620+ | AppTy g ( tcrefOfTypeExtended, _) when not ( isByrefTy g thisTy) -> Some tcrefOfTypeExtended
621+ | _ -> None
622+ Some rs
623+ with e -> // Import of the ILType may fail, if so report the error and skip on
624+ errorRecovery e m
625+ None
626+ match thisTyconRef with
627+ | None -> ()
628+ | Some ( Some tcref) -> yield Choice1Of2( tcref, ilExtMem)
629+ | Some None -> yield Choice2Of2 ilExtMem ]
630+ else
631+ []
579632
580633/// Query the declared properties of a type (including inherited properties)
581634let IntrinsicPropInfosOfTypeInScope ( infoReader : InfoReader ) optFilter ad findFlag m ty =
0 commit comments