From 94ee5ed21641d65daf8c67d467a776728b2423f2 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 31 May 2023 14:16:57 +0200 Subject: [PATCH] Fix assertion: UnknownType for unresolved reference can still be nullable; only the SpecialType.Unknown cannot. --- .../TypeSystem/Implementation/NullabilityAnnotatedType.cs | 1 + ICSharpCode.Decompiler/TypeSystem/Implementation/UnknownType.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs index 41ae7ee70..abfd5b184 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs @@ -20,6 +20,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation // the NullabilityAnnotatedType wrapper only in some limited places. Debug.Assert(type is ITypeDefinition { IsReferenceType: not false } || type.Kind == TypeKind.Dynamic + || type.Kind == TypeKind.Unknown || (type is ITypeParameter && this is ITypeParameter)); this.nullability = nullability; } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/UnknownType.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/UnknownType.cs index 5db919db7..28a0f33b7 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/UnknownType.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/UnknownType.cs @@ -107,7 +107,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override IType ChangeNullability(Nullability nullability) { - if (nullability == Nullability.Oblivious) + if (nullability == Nullability.Oblivious || isReferenceType == false) return this; else return new NullabilityAnnotatedType(this, nullability);