Skip to content

Commit

Permalink
Merge pull request #20 from 0xced/fix-nullability-warnings
Browse files Browse the repository at this point in the history
Fix nullability warnings
  • Loading branch information
xoofx authored Jan 27, 2022
2 parents 65edf35 + 3192dea commit 9d4a830
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Tomlyn/Model/Accessors/DictionaryDynamicAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public SlowDictionaryAccessor(DynamicModelReadContext context, Type dictionaryTy
public override bool TryGetValue(object dictionary, object key, out object? value)
{
var parameters = new object?[2] { key, null };
var result = (bool)_methodTryGetValue.Invoke(dictionary, parameters);
var result = (bool)_methodTryGetValue.Invoke(dictionary, parameters)!;
value = parameters[1];
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Model/Accessors/ListDynamicAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public int GetCount(object list)
case TomlTableArray array:
return array.Count;
default:
return (int)_propCount!.GetValue(list);
return (int)_propCount!.GetValue(list)!;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tomlyn/Model/Accessors/StandardObjectDynamicAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override bool TryGetPropertyValue(SourceSpan span, object obj, string nam

public override bool TrySetPropertyValue(SourceSpan span, object obj, string name, object? value)
{
string? errorMessage = null;
string errorMessage = "Unknown error";
try
{
if (_props.TryGetValue(name, out var prop))
Expand All @@ -92,7 +92,7 @@ public override bool TrySetPropertyValue(SourceSpan span, object obj, string nam
errorMessage = $"The property value of type {value?.GetType().FullName} couldn't be converted to {prop.PropertyType} for the list property {TargetType.FullName}/{name}";
}
}
else
else if (listValue is not null)
{
foreach (var item in (IEnumerable)value)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Tomlyn/Model/SyntaxToModelTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,9 @@ private ReferenceEqualityComparer()
{
}

#pragma warning disable CS0108, CS0114
public bool Equals(object x, object y)
#pragma warning restore CS0108, CS0114
#pragma warning disable CS0108
public bool Equals(object? x, object? y)
#pragma warning restore CS0108
{
return ReferenceEquals(x, y);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Tomlyn/Syntax/SyntaxValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ public ObjectPath Clone()
return (ObjectPath) MemberwiseClone();
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
var other = (ObjectPath) obj;
if (other.Count != Count) return false;
var other = obj as ObjectPath;
if (other?.Count != Count) return false;
if (other._hashCode != _hashCode) return false;
for (int i = 0; i < Count; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/TextPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public bool Equals(TextPosition other)
return Offset == other.Offset && Column == other.Column && Line == other.Line;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is TextPosition && Equals((TextPosition) obj);
Expand Down
32 changes: 16 additions & 16 deletions src/Tomlyn/TomlDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,78 +66,78 @@ TypeCode IConvertible.GetTypeCode()
}

[ExcludeFromCodeCoverage]
bool IConvertible.ToBoolean(IFormatProvider provider)
bool IConvertible.ToBoolean(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
byte IConvertible.ToByte(IFormatProvider provider)
byte IConvertible.ToByte(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
char IConvertible.ToChar(IFormatProvider provider)
char IConvertible.ToChar(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
DateTime IConvertible.ToDateTime(IFormatProvider provider)
DateTime IConvertible.ToDateTime(IFormatProvider? provider)
{
return DateTime.DateTime;
}

[ExcludeFromCodeCoverage]
decimal IConvertible.ToDecimal(IFormatProvider provider)
decimal IConvertible.ToDecimal(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
double IConvertible.ToDouble(IFormatProvider provider)
double IConvertible.ToDouble(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
short IConvertible.ToInt16(IFormatProvider provider)
short IConvertible.ToInt16(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
int IConvertible.ToInt32(IFormatProvider provider)
int IConvertible.ToInt32(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
long IConvertible.ToInt64(IFormatProvider provider)
long IConvertible.ToInt64(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
sbyte IConvertible.ToSByte(IFormatProvider provider)
sbyte IConvertible.ToSByte(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
float IConvertible.ToSingle(IFormatProvider provider)
float IConvertible.ToSingle(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
string IConvertible.ToString(IFormatProvider provider)
string IConvertible.ToString(IFormatProvider? provider)
{
throw new NotSupportedException();
}

object IConvertible.ToType(Type conversionType, IFormatProvider provider)
object IConvertible.ToType(Type conversionType, IFormatProvider? provider)
{
if (conversionType == typeof(DateTime))
{
Expand Down Expand Up @@ -165,19 +165,19 @@ object IConvertible.ToType(Type conversionType, IFormatProvider provider)
}

[ExcludeFromCodeCoverage]
ushort IConvertible.ToUInt16(IFormatProvider provider)
ushort IConvertible.ToUInt16(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
uint IConvertible.ToUInt32(IFormatProvider provider)
uint IConvertible.ToUInt32(IFormatProvider? provider)
{
throw new NotSupportedException();
}

[ExcludeFromCodeCoverage]
ulong IConvertible.ToUInt64(IFormatProvider provider)
ulong IConvertible.ToUInt64(IFormatProvider? provider)
{
throw new NotSupportedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/TomlModelOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ private static object DefaultCreateInstanceImpl(Type type, ObjectKind kind)
}
}

return Activator.CreateInstance(type);
return Activator.CreateInstance(type) ?? throw new InvalidOperationException($"Failed to create an instance of type '{type.FullName}'");
}
}

0 comments on commit 9d4a830

Please sign in to comment.