Browse Source

Fix #1442: Allow "dynamic?" in the type system.

pull/1471/head
Daniel Grunwald 6 years ago
parent
commit
b7a3c8d640
  1. 1
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullableRefTypes.cs
  2. 9
      ICSharpCode.Decompiler/TypeSystem/Implementation/DummyTypeParameter.cs
  3. 1
      ICSharpCode.Decompiler/TypeSystem/Implementation/NullabilityAnnotatedType.cs
  4. 8
      ICSharpCode.Decompiler/TypeSystem/SpecialType.cs

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

@ -7,6 +7,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -7,6 +7,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
private string field_string;
private string? field_nullable_string;
private dynamic? field_nullable_dynamic;
private Dictionary<string?, string> field_generic;
private (string, string?, string) field_tuple;

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

@ -168,5 +168,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -168,5 +168,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
bool ITypeParameter.HasValueTypeConstraint => false;
bool ITypeParameter.HasUnmanagedConstraint => false;
Nullability ITypeParameter.NullabilityConstraint => Nullability.Oblivious;
public override IType ChangeNullability(Nullability nullability)
{
if (nullability == Nullability.Oblivious) {
return this;
} else {
return new NullabilityAnnotatedTypeParameter(this, nullability);
}
}
}
}

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

@ -18,6 +18,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -18,6 +18,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
// Due to IType -> concrete type casts all over the type system, we can insert
// the NullabilityAnnotatedType wrapper only in some limited places.
Debug.Assert(type is ITypeDefinition
|| type.Kind == TypeKind.Dynamic
|| (type is ITypeParameter && this is ITypeParameter));
this.nullability = nullability;
}

8
ICSharpCode.Decompiler/TypeSystem/SpecialType.cs

@ -101,5 +101,13 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -101,5 +101,13 @@ namespace ICSharpCode.Decompiler.TypeSystem
{
return 81625621 ^ (int)kind;
}
public override IType ChangeNullability(Nullability nullability)
{
if (nullability == base.Nullability)
return this;
else
return new NullabilityAnnotatedType(this, nullability);
}
}
}

Loading…
Cancel
Save