From 89ea6c3675cfa56733aa14662e87a464c9501a27 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 6 Aug 2019 00:25:08 +0200 Subject: [PATCH] Fix TypeErasure not removing all nullability annotations. --- .../TypeSystem/NormalizeTypeVisitor.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/ICSharpCode.Decompiler/TypeSystem/NormalizeTypeVisitor.cs b/ICSharpCode.Decompiler/TypeSystem/NormalizeTypeVisitor.cs index 291eeac47..0f8d8a2a4 100644 --- a/ICSharpCode.Decompiler/TypeSystem/NormalizeTypeVisitor.cs +++ b/ICSharpCode.Decompiler/TypeSystem/NormalizeTypeVisitor.cs @@ -21,16 +21,6 @@ namespace ICSharpCode.Decompiler.TypeSystem RemoveNullability = true, }; - internal static readonly NormalizeTypeVisitor RemoveModifiersAndNullability = new NormalizeTypeVisitor { - ReplaceClassTypeParametersWithDummy = false, - ReplaceMethodTypeParametersWithDummy = false, - DynamicAndObject = false, - TupleToUnderlyingType = false, - RemoveModOpt = true, - RemoveModReq = true, - RemoveNullability = true, - }; - public bool EquivalentTypes(IType a, IType b) { a = a.AcceptVisitor(this); @@ -52,6 +42,8 @@ namespace ICSharpCode.Decompiler.TypeSystem return DummyTypeParameter.GetMethodTypeParameter(type.Index); } else if (type.OwnerType == SymbolKind.TypeDefinition && ReplaceClassTypeParametersWithDummy) { return DummyTypeParameter.GetClassTypeParameter(type.Index); + } else if (RemoveNullability && type is NullabilityAnnotatedTypeParameter natp) { + return natp.TypeWithoutAnnotation.AcceptVisitor(this); } else { return base.VisitTypeParameter(type); } @@ -82,7 +74,7 @@ namespace ICSharpCode.Decompiler.TypeSystem public override IType VisitNullabilityAnnotatedType(NullabilityAnnotatedType type) { if (RemoveNullability) - return base.VisitNullabilityAnnotatedType(type).ChangeNullability(Nullability.Oblivious); + return type.TypeWithoutAnnotation.AcceptVisitor(this); else return base.VisitNullabilityAnnotatedType(type); }