未验证 提交 558cca1a 编写于 作者: F Florian Verdonck 提交者: GitHub

Don't emit IsReadOnlyAttribute if not available. (#14276)

Fixes https://github.com/dotnet/fsharp/issues/14275
上级 bb909619
......@@ -611,7 +611,10 @@ let GenReadOnlyAttribute (g: TcGlobals) =
mkILCustomAttribute (g.attrib_IsReadOnlyAttribute.TypeRef, [], [], [])
let GenReadOnlyAttributeIfNecessary (g: TcGlobals) ty =
let add = isInByrefTy g ty && g.attrib_IsReadOnlyAttribute.TyconRef.CanDeref
let add =
g.isSystem_Runtime_CompilerServices_IsReadOnlyAttributeAvailable
&& isInByrefTy g ty
&& g.attrib_IsReadOnlyAttribute.TyconRef.CanDeref
if add then
let attr = GenReadOnlyAttribute g
......@@ -2120,7 +2123,11 @@ type AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbu
let ilMethods =
[
for propName, fldName, fldTy in flds ->
let attrs = if isStruct then [ GenReadOnlyAttribute g ] else []
let attrs =
if g.isSystem_Runtime_CompilerServices_IsReadOnlyAttributeAvailable && isStruct then
[ GenReadOnlyAttribute g ]
else
[]
mkLdfldMethodDef ("get_" + propName, ILMemberAccess.Public, false, ilTy, fldName, fldTy, attrs)
|> g.AddMethodGeneratedAttributes
......@@ -10878,7 +10885,11 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =
let isStruct = isStructTyconRef tcref
let attrs =
if isStruct && not isStatic then
if
g.isSystem_Runtime_CompilerServices_IsReadOnlyAttributeAvailable
&& isStruct
&& not isStatic
then
[ GenReadOnlyAttribute g ]
else
[]
......
......@@ -1719,6 +1719,9 @@ type TcGlobals(
/// Indicates if we can use System.Array.Empty when emitting IL for empty array literals
member val isArrayEmptyAvailable = v_Array_tcref.ILTyconRawMetadata.Methods.FindByName "Empty" |> List.isEmpty |> not
/// Indicates if we can emit the System.Runtime.CompilerServices.IsReadOnlyAttribute
member val isSystem_Runtime_CompilerServices_IsReadOnlyAttributeAvailable = tryFindSysTypeCcu sysCompilerServices "IsReadOnlyAttribute" |> Option.isSome
member _.FindSysTyconRef path nm = findSysTyconRef path nm
member _.TryFindSysTyconRef path nm = tryFindSysTyconRef path nm
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册