Browse Source

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

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

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

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

14
ICSharpCode.Decompiler/TypeSystem/ParameterizedType.cs

@ -140,10 +140,20 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -140,10 +140,20 @@ namespace ICSharpCode.Decompiler.TypeSystem
return b.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;

Loading…
Cancel
Save