Browse Source

Fix #1597: Incorrect handling of nullability annotations during generic type substitution.

pull/1612/head
Daniel Grunwald 7 years ago
parent
commit
afde03a04d
  1. 7
      ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs
  2. 12
      ICSharpCode.Decompiler/TypeSystem/ParameterizedType.cs

7
ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs

@ -53,11 +53,16 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IType newBase = baseType.AcceptVisitor(visitor); IType newBase = baseType.AcceptVisitor(visitor);
if (newBase != baseType) { if (newBase != baseType) {
if (newBase.Nullability == Nullability.Nullable) { if (newBase.Nullability == Nullability.Nullable) {
// T?! -> T? // `T!` with substitution T=`U?` becomes `U?`
// This happens during type substitution for generic methods. // This happens during type substitution for generic methods.
return newBase; return newBase;
} }
if (newBase.Kind == TypeKind.TypeParameter || newBase.IsReferenceType == true) {
return newBase.ChangeNullability(nullability); return newBase.ChangeNullability(nullability);
} else {
// `T!` with substitution T=`int` becomes `int`, not `int!`
return newBase;
}
} else { } else {
return this; return this;
} }

12
ICSharpCode.Decompiler/TypeSystem/ParameterizedType.cs

@ -143,7 +143,17 @@ namespace ICSharpCode.Decompiler.TypeSystem
public override string ToString() public override string ToString()
{ {
return ReflectionName; StringBuilder b = new StringBuilder(genericType.ToString());
b.Append('[');
for (int i = 0; i < typeArguments.Length; i++) {
if (i > 0)
b.Append(',');
b.Append('[');
b.Append(typeArguments[i].ToString());
b.Append(']');
}
b.Append(']');
return b.ToString();
} }
public IReadOnlyList<IType> TypeArguments => typeArguments; public IReadOnlyList<IType> TypeArguments => typeArguments;

Loading…
Cancel
Save