Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a number of nullable warnings. #1035

Merged
merged 2 commits into from Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions .editorconfig
Expand Up @@ -252,11 +252,3 @@ csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false








8 changes: 5 additions & 3 deletions Ix.NET/Source/AsyncQueryableGenerator.t4
Expand Up @@ -174,7 +174,7 @@ foreach (var m in asyncEnumerableType.GetMethods()
{
infoName += "__" + string.Join("_", genArgs.Select(a => a.Name));
infoTypeArgs = "(" + string.Join(", ", genArgs.Select(a => "Type " + a.Name)) + ")";
infoToGeneric = ".GetGenericMethodDefinition()";
infoToGeneric = "!.GetGenericMethodDefinition()";
infoMakeGeneric = ".MakeGenericMethod(" + string.Join(", ", genArgs.Select(a => a.Name)) + ")";
infoGenArgs = "<" + string.Join(", ", genArgs.Select(_ => "object")) + ">";
}
Expand Down Expand Up @@ -281,14 +281,16 @@ foreach (var m in asyncEnumerableType.GetMethods()
}

var expr = "Expression.Call(" + mtd + ", " + string.Join(", ", quotedArgs) + ")";

var cons = name.StartsWith("ToDictionary") ? " where TKey : notnull" : "";
#>
private static MethodInfo s_<#=infoName#>;
private static MethodInfo? s_<#=infoName#>;

private static MethodInfo <#=infoName#><#=infoTypeArgs#> =>
(s_<#=infoName#> ??
(s_<#=infoName#> = new Func<<#=infoSignature#>>(<#=m.Name#><#=infoGenArgs#>).GetMethodInfo()<#=infoToGeneric#>))<#=infoMakeGeneric#>;

public static <#=ret#> <#=name#>(<#=pars#>)
public static <#=ret#> <#=name#>(<#=pars#>)<#=cons#>
{
<#
var any = false;
Expand Down
4 changes: 3 additions & 1 deletion Ix.NET/Source/FasterLinq/Program.cs
@@ -1,7 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections;
using System.Collections.Generic;
Expand Down
Expand Up @@ -5,7 +5,6 @@
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>


<ItemGroup>
<Content Include="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -24,7 +23,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.9.0" />

<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>

Expand Down

Large diffs are not rendered by default.

Expand Up @@ -113,16 +113,16 @@ public void DisposeAfterCreation()
enumerable?.Dispose();
}

private class DisposeCounter : IAsyncEnumerable<object>
private class DisposeCounter : IAsyncEnumerable<object?>
{
public int DisposeCount { get; private set; }

public IAsyncEnumerator<object> GetAsyncEnumerator(CancellationToken cancellationToken)
public IAsyncEnumerator<object?> GetAsyncEnumerator(CancellationToken cancellationToken)
{
return new Enumerator(this);
}

private class Enumerator : IAsyncEnumerator<object>
private class Enumerator : IAsyncEnumerator<object?>
{
private readonly DisposeCounter _disposeCounter;

Expand All @@ -142,7 +142,7 @@ public ValueTask<bool> MoveNextAsync()
return new ValueTask<bool>(Task.Factory.StartNew(() => false));
}

public object Current { get; private set; }
public object? Current { get; private set; }
}
}
}
Expand Down
Expand Up @@ -2,10 +2,9 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net461;netcoreapp3.0</TargetFrameworks>
<NoWarn>$(NoWarn);CS0618</NoWarn>
<NoWarn>$(NoWarn);CS0618;CS8603;CS8625</NoWarn>
</PropertyGroup>


<ItemGroup>
<Content Include="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -22,7 +21,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="xunit" Version="2.4.1" />

</ItemGroup>

<ItemGroup>
Expand Down
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -103,9 +102,6 @@ private sealed class DistinctAsyncIterator<TSource, TKey> : AsyncIterator<TSourc

public DistinctAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer)
{
Debug.Assert(source != null);
Debug.Assert(keySelector != null);

_source = source;
_keySelector = keySelector;
_comparer = comparer;
Expand Down Expand Up @@ -251,9 +247,6 @@ private sealed class DistinctAsyncIteratorWithTask<TSource, TKey> : AsyncIterato

public DistinctAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
{
Debug.Assert(source != null);
Debug.Assert(keySelector != null);

_source = source;
_keySelector = keySelector;
_comparer = comparer;
Expand Down Expand Up @@ -400,9 +393,6 @@ private sealed class DistinctAsyncIteratorWithTaskAndCancellation<TSource, TKey>

public DistinctAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey>? comparer)
{
Debug.Assert(source != null);
Debug.Assert(keySelector != null);

_source = source;
_keySelector = keySelector;
_comparer = comparer;
Expand Down
Expand Up @@ -49,7 +49,7 @@ public ValueTask<bool> MoveNextAsync()

_once = true;
var task = new TaskCompletionSource<bool>();
_registration = _token.Register(state => ((TaskCompletionSource<bool>)state).SetCanceled(), task);
_registration = _token.Register(state => ((TaskCompletionSource<bool>)state!).SetCanceled(), task);
return new ValueTask<bool>(task.Task);
}
}
Expand Down
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;

namespace System.Linq
Expand Down Expand Up @@ -50,8 +49,6 @@ private sealed class OnErrorResumeNextAsyncIterator<TSource> : AsyncIterator<TSo

public OnErrorResumeNextAsyncIterator(IEnumerable<IAsyncEnumerable<TSource>> sources)
{
Debug.Assert(sources != null);

_sources = sources;
}

Expand Down
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -34,8 +33,6 @@ private sealed class TimeoutAsyncIterator<TSource> : AsyncIterator<TSource>

public TimeoutAsyncIterator(IAsyncEnumerable<TSource> source, TimeSpan timeout)
{
Debug.Assert(source != null);

_source = source;
_timeout = timeout;
}
Expand Down Expand Up @@ -99,7 +96,7 @@ protected override async ValueTask<bool> MoveNextCore()
// REVIEW: Should exceptions reported by a timed out MoveNextAsync operation come out
// when attempting to call DisposeAsync?

_loserTask = next.ContinueWith((_, state) => ((IAsyncDisposable)state).DisposeAsync().AsTask(), _enumerator);
_loserTask = next.ContinueWith((_, state) => ((IAsyncDisposable)state!).DisposeAsync().AsTask(), _enumerator);

throw new TimeoutException();
}
Expand Down
Expand Up @@ -2,10 +2,9 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<NoWarn>$(NoWarn);CS0618</NoWarn>
<NoWarn>$(NoWarn);CS0618;CS8603;CS8625</NoWarn>
</PropertyGroup>


<ItemGroup>
<Content Include="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -23,7 +22,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.9.0" />

<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>

Expand Down
Expand Up @@ -26,12 +26,12 @@ public void Using1()
Assert.Null(d);

var d1 = default(MyDisposable);
xs.ForEach(_ => { d1 = d; Assert.NotNull(d1); Assert.False(d1.Done); });
Assert.True(d1.Done);
xs.ForEach(_ => { d1 = d; Assert.NotNull(d1); Assert.False(d1!.Done); });
Assert.True(d1!.Done);

var d2 = default(MyDisposable);
xs.ForEach(_ => { d2 = d; Assert.NotNull(d2); Assert.False(d2.Done); });
Assert.True(d2.Done);
xs.ForEach(_ => { d2 = d; Assert.NotNull(d2); Assert.False(d2!.Done); });
Assert.True(d2!.Done);

Assert.NotSame(d1, d2);
}
Expand All @@ -45,7 +45,7 @@ public void Using2()
Assert.Null(d);

AssertThrows<MyException>(() => xs.ForEach(_ => { }));
Assert.True(d.Done);
Assert.True(d!.Done);
}

[Fact]
Expand All @@ -57,7 +57,7 @@ public void Using3()
Assert.Null(d);

AssertThrows<MyException>(() => xs.ForEach(_ => { }));
Assert.True(d.Done);
Assert.True(d!.Done);
}

private sealed class MyDisposable : IDisposable
Expand Down
Expand Up @@ -82,7 +82,7 @@ public static IEnumerable<TSource> Catch<TSource>(this IEnumerable<TSource> firs
{
while (true)
{
var c = default(TSource);
TSource c;

try
{
Expand Down Expand Up @@ -121,7 +121,7 @@ private static IEnumerable<TSource> CatchCore<TSource>(IEnumerable<IEnumerable<T

while (true)
{
var c = default(TSource);
TSource c;

try
{
Expand Down
Expand Up @@ -115,7 +115,7 @@ private sealed class MemoizedBuffer<T> : IBuffer<T>
{
private IRefCountList<T> _buffer;
private bool _disposed;
private Exception _error;
private Exception? _error;
private IEnumerator<T> _source;
private bool _stopped;

Expand Down
Expand Up @@ -61,9 +61,11 @@ public static IBuffer<TSource> Publish<TSource>(this IEnumerable<TSource> source

private sealed class PublishedBuffer<T> : IBuffer<T>
{
private readonly object _gate = new object();

private RefCountList<T> _buffer;
private bool _disposed;
private Exception _error;
private Exception? _error;
private IEnumerator<T> _source;
private bool _stopped;

Expand All @@ -81,7 +83,7 @@ public IEnumerator<T> GetEnumerator()
}

var i = default(int);
lock (_source)
lock (_gate)
{
i = _buffer.Count;
_buffer.ReaderCount++;
Expand All @@ -102,7 +104,7 @@ IEnumerator IEnumerable.GetEnumerator()

public void Dispose()
{
lock (_source)
lock (_gate)
{
if (!_disposed)
{
Expand Down Expand Up @@ -131,7 +133,7 @@ private IEnumerator<T> GetEnumeratorCore(int i)
var hasValue = default(bool);
var current = default(T);

lock (_source)
lock (_gate)
{
if (i >= _buffer.Count)
{
Expand Down
4 changes: 2 additions & 2 deletions Ix.NET/Source/System.Interactive/System/Linq/Yielder.cs
Expand Up @@ -9,7 +9,7 @@ namespace System.Linq
internal sealed class Yielder<T> : IYielder<T>, IAwaitable, IAwaiter
{
private readonly Action<Yielder<T>> _create;
private Action _continuation;
private Action? _continuation;
private bool _hasValue;
private bool _running;
private bool _stopped;
Expand Down Expand Up @@ -62,7 +62,7 @@ public bool MoveNext()
else
{
_hasValue = false;
_continuation();
_continuation!();
}

return !_stopped && _hasValue;
Expand Down
Expand Up @@ -5,7 +5,6 @@
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>


<ItemGroup>
<Content Include="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Expand Up @@ -133,7 +133,7 @@ public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken token)
/// Gets a string representation of the enumerable sequence.
/// </summary>
/// <returns>String representation of the enumerable sequence.</returns>
public override string ToString()
public override string? ToString()
{
if (!(_expression is ConstantExpression ce) || ce.Value != this)
{
Expand Down