Skip to content

Commit 46d83e3

Browse files
authored
Merge pull request #1376 from dotnet/dev/bartde/fix_warnings
Fix a number of warnings.
2 parents 460c58f + adae5cf commit 46d83e3

18 files changed

+51
-49
lines changed

Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static partial class Scheduler
7070
{
7171
if (scheduler is IServiceProvider svc)
7272
{
73-
return (T)svc.GetService(typeof(T));
73+
return (T?)svc.GetService(typeof(T));
7474
}
7575

7676
return null;

Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static IDisposable Schedule(this IScheduler scheduler, Action action)
3434
// the anonymous lambda can be replaced by the method group again. Until then,
3535
// to avoid the repetition of code, the call to Invoke is left intact.
3636
// Watch https://github.com/dotnet/roslyn/issues/5835
37-
return scheduler.Schedule(action, static (s, a) => Invoke(s, a));
37+
return scheduler.Schedule(action, static (_, a) => Invoke(a));
3838
}
3939

4040
/// <summary>
@@ -109,7 +109,7 @@ public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime,
109109
}
110110

111111
// See note above.
112-
return scheduler.Schedule(action, dueTime, static (s, a) => Invoke(s, a));
112+
return scheduler.Schedule(action, dueTime, static (_, a) => Invoke(a));
113113
}
114114

115115
/// <summary>
@@ -134,7 +134,7 @@ internal static IDisposable ScheduleAction<TState>(this IScheduler scheduler, TS
134134
}
135135

136136
// See note above.
137-
return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
137+
return scheduler.Schedule((state, action), dueTime, static (_, tuple) => Invoke(tuple));
138138
}
139139

140140
/// <summary>
@@ -154,7 +154,7 @@ internal static IDisposable ScheduleAction<TState>(this IScheduler scheduler, TS
154154
throw new ArgumentNullException(nameof(action));
155155

156156
// See note above.
157-
return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
157+
return scheduler.Schedule((state, action), dueTime, static (_, tuple) => Invoke(tuple));
158158
}
159159

160160
/// <summary>
@@ -178,7 +178,7 @@ public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset due
178178
}
179179

180180
// See note above.
181-
return scheduler.Schedule(action, dueTime, static (s, a) => Invoke(s, a));
181+
return scheduler.Schedule(action, dueTime, static (_, a) => Invoke(a));
182182
}
183183

184184
/// <summary>
@@ -203,7 +203,7 @@ internal static IDisposable ScheduleAction<TState>(this IScheduler scheduler, TS
203203
}
204204

205205
// See note above.
206-
return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
206+
return scheduler.Schedule((state, action), dueTime, static (_, tuple) => Invoke(tuple));
207207
}
208208

209209
/// <summary>
@@ -223,7 +223,7 @@ internal static IDisposable ScheduleAction<TState>(this IScheduler scheduler, TS
223223
throw new ArgumentNullException(nameof(action));
224224

225225
// See note above.
226-
return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
226+
return scheduler.Schedule((state, action), dueTime, static (_, tuple) => Invoke(tuple));
227227
}
228228

229229
/// <summary>
@@ -248,19 +248,19 @@ public static IDisposable ScheduleLongRunning(this ISchedulerLongRunning schedul
248248
return scheduler.ScheduleLongRunning(action, static (a, c) => a(c));
249249
}
250250

251-
private static IDisposable Invoke(IScheduler scheduler, Action action)
251+
private static IDisposable Invoke(Action action)
252252
{
253253
action();
254254
return Disposable.Empty;
255255
}
256256

257-
private static IDisposable Invoke<TState>(IScheduler scheduler, (TState state, Action<TState> action) tuple)
257+
private static IDisposable Invoke<TState>((TState state, Action<TState> action) tuple)
258258
{
259259
tuple.action(tuple.state);
260260
return Disposable.Empty;
261261
}
262262

263-
private static IDisposable Invoke<TState>(IScheduler scheduler, (TState state, Func<TState, IDisposable> action) tuple)
263+
private static IDisposable Invoke<TState>((TState state, Func<TState, IDisposable> action) tuple)
264264
{
265265
return tuple.action(tuple.state);
266266
}

Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.ObserveOn.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ public override void OnCompleted()
112112
_context.Post(OnCompletedPosted, state: null);
113113
}
114114

115-
private void OnNextPosted(object value)
115+
private void OnNextPosted(object? value)
116116
{
117-
ForwardOnNext((TSource)value);
117+
ForwardOnNext((TSource)value!);
118118
}
119119

120-
private void OnErrorPosted(object error)
120+
private void OnErrorPosted(object? error)
121121
{
122-
ForwardOnError((Exception)error);
122+
ForwardOnError((Exception)error!);
123123
}
124124

125-
private void OnCompletedPosted(object ignored)
125+
private void OnCompletedPosted(object? ignored)
126126
{
127127
ForwardOnCompleted();
128128
}

Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.Extensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static IDisposable ScheduleRelative<TAbsolute, TRelative>(this VirtualTim
3838
// an anonymous delegate will allow delegate caching.
3939
// Watch https://github.com/dotnet/roslyn/issues/5835 for compiler
4040
// support for caching delegates from method groups.
41-
return scheduler.ScheduleRelative(action, dueTime, static (s, a) => Invoke(s, a));
41+
return scheduler.ScheduleRelative(action, dueTime, static (_, a) => Invoke(a));
4242
}
4343

4444
/// <summary>
@@ -64,10 +64,10 @@ public static IDisposable ScheduleAbsolute<TAbsolute, TRelative>(this VirtualTim
6464
throw new ArgumentNullException(nameof(action));
6565
}
6666

67-
return scheduler.ScheduleAbsolute(action, dueTime, static (s, a) => Invoke(s, a));
67+
return scheduler.ScheduleAbsolute(action, dueTime, static (_, a) => Invoke(a));
6868
}
6969

70-
private static IDisposable Invoke(IScheduler scheduler, Action action)
70+
private static IDisposable Invoke(Action action)
7171
{
7272
action();
7373
return Disposable.Empty;

Rx.NET/Source/src/System.Reactive/Internal/HostLifecycleNotifications.Windows.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace System.Reactive.PlatformServices
1010
{
1111
internal class HostLifecycleNotifications : IHostLifecycleNotifications
1212
{
13-
private EventHandler<SuspendingEventArgs> _suspending;
14-
private EventHandler<object> _resuming;
13+
private EventHandler<SuspendingEventArgs>? _suspending;
14+
private EventHandler<object>? _resuming;
1515

1616
public event EventHandler<HostSuspendingEventArgs> Suspending
1717
{

Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ protected override void Dispose(bool disposing)
436436
/// _queue field is not re-read from memory unnecessarily
437437
/// due to the memory barriers inside TryDequeue mandating it
438438
/// despite the field is read-only.</param>
439-
private void Clear(ConcurrentQueue<T> q)
439+
private static void Clear(ConcurrentQueue<T> q)
440440
{
441441
while (q.TryDequeue(out var _))
442442
{

Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ protected override TDelegate GetHandler(Action<TEventArgs> onNext)
178178

179179
if (_conversion == null)
180180
{
181-
handler = ReflectionUtils.CreateDelegate<TDelegate>(onNext, typeof(Action<TEventArgs>).GetMethod(nameof(Action<TEventArgs>.Invoke)));
181+
handler = ReflectionUtils.CreateDelegate<TDelegate>(onNext, typeof(Action<TEventArgs>).GetMethod(nameof(Action<TEventArgs>.Invoke))!);
182182
}
183183
else
184184
{

Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected override TDelegate GetHandler(Action<EventPattern<TEventArgs>> onNext)
3737
if (_conversion == null)
3838
{
3939
Action<object, TEventArgs> h = (sender, eventArgs) => onNext(new EventPattern<TEventArgs>(sender, eventArgs));
40-
handler = ReflectionUtils.CreateDelegate<TDelegate>(h, typeof(Action<object, TEventArgs>).GetMethod(nameof(Action<object, TEventArgs>.Invoke)));
40+
handler = ReflectionUtils.CreateDelegate<TDelegate>(h, typeof(Action<object, TEventArgs>).GetMethod(nameof(Action<object, TEventArgs>.Invoke))!);
4141
}
4242
else
4343
{
@@ -58,7 +58,7 @@ public Impl(Action<TDelegate> addHandler, Action<TDelegate> removeHandler, ISche
5858
protected override TDelegate GetHandler(Action<EventPattern<TSender, TEventArgs>> onNext)
5959
{
6060
Action<TSender, TEventArgs> h = (sender, eventArgs) => onNext(new EventPattern<TSender, TEventArgs>(sender, eventArgs));
61-
return ReflectionUtils.CreateDelegate<TDelegate>(h, typeof(Action<TSender, TEventArgs>).GetMethod(nameof(Action<TSender, TEventArgs>.Invoke)));
61+
return ReflectionUtils.CreateDelegate<TDelegate>(h, typeof(Action<TSender, TEventArgs>).GetMethod(nameof(Action<TSender, TEventArgs>.Invoke))!);
6262
}
6363
}
6464

@@ -91,7 +91,7 @@ public Handler(object? target, Type delegateType, MethodInfo addMethod, MethodIn
9191
protected override Delegate GetHandler(Action<TResult> onNext)
9292
{
9393
Action<TSender, TEventArgs> h = (sender, eventArgs) => onNext(_getResult(sender, eventArgs));
94-
return ReflectionUtils.CreateDelegate(_delegateType, h, typeof(Action<TSender, TEventArgs>).GetMethod(nameof(Action<TSender, TEventArgs>.Invoke)));
94+
return ReflectionUtils.CreateDelegate(_delegateType, h, typeof(Action<TSender, TEventArgs>).GetMethod(nameof(Action<TSender, TEventArgs>.Invoke))!);
9595
}
9696

9797
protected override IDisposable AddHandler(Delegate handler)

Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections.Generic;
6+
using System.Reactive.Concurrency;
67
using System.Reactive.Disposables;
78
using System.Threading;
89
using System.Threading.Tasks;
@@ -629,7 +630,7 @@ private void OnCompletedTask(TSource value, Task<TCollection> task)
629630
{
630631
lock (_gate)
631632
{
632-
ForwardOnError(task.Exception.InnerException);
633+
ForwardOnError(TaskHelpers.GetSingleException(task));
633634
}
634635

635636
break;
@@ -786,7 +787,7 @@ private void OnCompletedTask(TSource value, int index, Task<TCollection> task)
786787
{
787788
lock (_gate)
788789
{
789-
ForwardOnError(task.Exception.InnerException);
790+
ForwardOnError(TaskHelpers.GetSingleException(task));
790791
}
791792

792793
break;
@@ -1532,7 +1533,7 @@ public override void OnNext(TSource value)
15321533
}
15331534
else
15341535
{
1535-
task.ContinueWith((closureTask, thisObject) => ((_)thisObject).OnCompletedTask(closureTask), this, _cts.Token);
1536+
task.ContinueWith((closureTask, thisObject) => ((_)thisObject!).OnCompletedTask(closureTask), this, _cts.Token);
15361537
}
15371538
}
15381539

@@ -1555,7 +1556,7 @@ private void OnCompletedTask(Task<TResult> task)
15551556
{
15561557
lock (_gate)
15571558
{
1558-
ForwardOnError(task.Exception.InnerException);
1559+
ForwardOnError(TaskHelpers.GetSingleException(task));
15591560
}
15601561

15611562
break;
@@ -1667,7 +1668,7 @@ public override void OnNext(TSource value)
16671668
}
16681669
else
16691670
{
1670-
task.ContinueWith((closureTask, thisObject) => ((_)thisObject).OnCompletedTask(closureTask), this, _cts.Token);
1671+
task.ContinueWith((closureTask, thisObject) => ((_)thisObject!).OnCompletedTask(closureTask), this, _cts.Token);
16711672
}
16721673
}
16731674

@@ -1690,7 +1691,7 @@ private void OnCompletedTask(Task<TResult> task)
16901691
{
16911692
lock (_gate)
16921693
{
1693-
ForwardOnError(task.Exception.InnerException);
1694+
ForwardOnError(TaskHelpers.GetSingleException(task));
16941695
}
16951696

16961697
break;

Rx.NET/Source/src/System.Reactive/Linq/Qbservable.Joins.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static QueryablePattern<TLeft, TRight> And<TLeft, TRight>(this IQbservabl
4545
#if CRIPPLED_REFLECTION
4646
InfoOf(() => And<TLeft, TRight>(default, default)),
4747
#else
48-
((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TLeft), typeof(TRight)),
48+
((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TLeft), typeof(TRight)),
4949
#endif
5050
left.Expression,
5151
GetSourceExpression(right)
@@ -80,7 +80,7 @@ public static QueryablePlan<TResult> Then<TSource, TResult>(this IQbservable<TSo
8080
#if CRIPPLED_REFLECTION
8181
InfoOf(() => Then<TSource, TResult>(default, default)),
8282
#else
83-
((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)),
83+
((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TSource), typeof(TResult)),
8484
#endif
8585
source.Expression,
8686
selector
@@ -114,7 +114,7 @@ public static IQbservable<TResult> When<TResult>(this IQbservableProvider provid
114114
#if CRIPPLED_REFLECTION
115115
InfoOf(() => When<TResult>(default, default)),
116116
#else
117-
((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
117+
((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TResult)),
118118
#endif
119119
Expression.Constant(provider, typeof(IQbservableProvider)),
120120
Expression.NewArrayInit(
@@ -151,7 +151,7 @@ public static IQbservable<TResult> When<TResult>(this IQbservableProvider provid
151151
#if CRIPPLED_REFLECTION
152152
InfoOf(() => When(default, default(IEnumerable<QueryablePlan<TResult>>))),
153153
#else
154-
((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)),
154+
((MethodInfo)MethodBase.GetCurrentMethod()!).MakeGenericMethod(typeof(TResult)),
155155
#endif
156156
Expression.Constant(provider, typeof(IQbservableProvider)),
157157
Expression.Constant(plans, typeof(IEnumerable<QueryablePlan<TResult>>))

0 commit comments

Comments
 (0)