Browse Source

Fix dynamic type index calculation in `ApplyAttributeTypeVisitor`

pull/2840/head
ElektroKill 3 years ago
parent
commit
0b9d546f46
No known key found for this signature in database
GPG Key ID: 7E3C5C084E40E3EC
  1. 1
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs
  2. 15
      ICSharpCode.Decompiler/TypeSystem/ApplyAttributeTypeVisitor.cs
  3. 3
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs
  4. 5
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs

1
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs

@ -47,6 +47,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
private static dynamic field; private static dynamic field;
private static volatile dynamic volatileField;
private static object objectField; private static object objectField;
public dynamic Property { get; set; } public dynamic Property { get; set; }

15
ICSharpCode.Decompiler/TypeSystem/ApplyAttributeTypeVisitor.cs

@ -1,4 +1,4 @@
// Copyright (c) 2018 Daniel Grunwald // Copyright (c) 2018 Daniel Grunwald
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software // software and associated documentation files (the "Software"), to deal in the Software
@ -40,8 +40,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
SRM.MetadataReader metadata, SRM.MetadataReader metadata,
TypeSystemOptions options, TypeSystemOptions options,
Nullability nullableContext, Nullability nullableContext,
bool typeChildrenOnly = false, bool typeChildrenOnly = false)
bool isSignatureReturnType = false)
{ {
bool hasDynamicAttribute = false; bool hasDynamicAttribute = false;
bool[] dynamicAttributeData = null; bool[] dynamicAttributeData = null;
@ -134,14 +133,6 @@ namespace ICSharpCode.Decompiler.TypeSystem
options, tupleElementNames, options, tupleElementNames,
nullability, nullableAttributeData nullability, nullableAttributeData
); );
if (isSignatureReturnType && hasDynamicAttribute
&& inputType.SkipModifiers().Kind == TypeKind.ByReference
&& attributes.Value.HasKnownAttribute(metadata, KnownAttribute.IsReadOnly))
{
// crazy special case: `ref readonly` return takes one dynamic index more than
// a non-readonly `ref` return.
visitor.dynamicTypeIndex++;
}
if (typeChildrenOnly) if (typeChildrenOnly)
{ {
return inputType.VisitChildren(visitor); return inputType.VisitChildren(visitor);
@ -190,6 +181,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public override IType VisitModOpt(ModifiedType type) public override IType VisitModOpt(ModifiedType type)
{ {
dynamicTypeIndex++;
if ((options & TypeSystemOptions.KeepModifiers) != 0) if ((options & TypeSystemOptions.KeepModifiers) != 0)
return base.VisitModOpt(type); return base.VisitModOpt(type);
else else
@ -198,6 +190,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public override IType VisitModReq(ModifiedType type) public override IType VisitModReq(ModifiedType type)
{ {
dynamicTypeIndex++;
if ((options & TypeSystemOptions.KeepModifiers) != 0) if ((options & TypeSystemOptions.KeepModifiers) != 0)
return base.VisitModReq(type); return base.VisitModReq(type);
else else

3
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs

@ -1,4 +1,4 @@
// Copyright (c) 2018 Daniel Grunwald // Copyright (c) 2018 Daniel Grunwald
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software // software and associated documentation files (the "Software"), to deal in the Software
@ -225,7 +225,6 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
if (ty is ModifiedType mod && mod.Modifier.Name == "IsVolatile" && mod.Modifier.Namespace == "System.Runtime.CompilerServices") if (ty is ModifiedType mod && mod.Modifier.Name == "IsVolatile" && mod.Modifier.Namespace == "System.Runtime.CompilerServices")
{ {
Volatile.Write(ref this.isVolatile, true); Volatile.Write(ref this.isVolatile, true);
ty = mod.ElementType;
} }
ty = ApplyAttributeTypeVisitor.ApplyAttributesToType(ty, Compilation, ty = ApplyAttributeTypeVisitor.ApplyAttributesToType(ty, Compilation,
fieldDef.GetCustomAttributes(), metadata, module.OptionsForEntity(this), fieldDef.GetCustomAttributes(), metadata, module.OptionsForEntity(this),

5
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs

@ -1,4 +1,4 @@
// Copyright (c) 2018 Daniel Grunwald // Copyright (c) 2018 Daniel Grunwald
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software // software and associated documentation files (the "Software"), to deal in the Software
@ -271,8 +271,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
} }
Debug.Assert(i == parameters.Length); Debug.Assert(i == parameters.Length);
var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType, var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType,
module.Compilation, returnTypeAttributes, metadata, typeSystemOptions, nullableContext, module.Compilation, returnTypeAttributes, metadata, typeSystemOptions, nullableContext);
isSignatureReturnType: true);
return (returnType, parameters, signature.ReturnType as ModifiedType); return (returnType, parameters, signature.ReturnType as ModifiedType);
} }
#endregion #endregion

Loading…
Cancel
Save