From 938428d2641705fbb2f7cba5861c2b5d36a49907 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 27 Nov 2024 21:37:25 +0800 Subject: [PATCH] Resolve new nullability warnings --- osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs | 4 ++-- osu.Game/Graphics/UserInterface/StatefulMenuItem.cs | 4 ++-- osu.Game/Screens/Edit/Setup/ColoursSection.cs | 2 +- osu.Game/Screens/OnlinePlay/Match/DrawableMatchRoom.cs | 5 +++++ osu.Game/Screens/Select/SongSelect.cs | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs b/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs index 4206f77c9865..f917203b6b0f 100644 --- a/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs @@ -37,7 +37,7 @@ protected override bool OnMouseDown(MouseDownEvent e) private partial class ToggleTextContainer : TextContainer { private readonly StatefulMenuItem menuItem; - private readonly Bindable state; + private readonly Bindable state; private readonly SpriteIcon stateIcon; public ToggleTextContainer(StatefulMenuItem menuItem) @@ -61,7 +61,7 @@ protected override void LoadComplete() state.BindValueChanged(updateState, true); } - private void updateState(ValueChangedEvent state) + private void updateState(ValueChangedEvent state) { var icon = menuItem.GetIconForState(state.NewValue); diff --git a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs index 9111cfb3aada..c3d8877ede53 100644 --- a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs @@ -53,7 +53,7 @@ protected StatefulMenuItem(LocalisableString text, Func? chang /// /// The state to retrieve the relevant icon for. /// The icon to be displayed for . - public abstract IconUsage? GetIconForState(object state); + public abstract IconUsage? GetIconForState(object? state); } public abstract class StatefulMenuItem : StatefulMenuItem @@ -97,7 +97,7 @@ protected StatefulMenuItem(LocalisableString text, Func? changeStateFunc, State.BindValueChanged(state => base.State.Value = state.NewValue); } - public sealed override IconUsage? GetIconForState(object state) => GetIconForState((T)state); + public sealed override IconUsage? GetIconForState(object? state) => GetIconForState((T)state!); /// /// Retrieves the icon to be displayed for a state. diff --git a/osu.Game/Screens/Edit/Setup/ColoursSection.cs b/osu.Game/Screens/Edit/Setup/ColoursSection.cs index 8de7f86523a7..f6c61daa69b4 100644 --- a/osu.Game/Screens/Edit/Setup/ColoursSection.cs +++ b/osu.Game/Screens/Edit/Setup/ColoursSection.cs @@ -66,7 +66,7 @@ protected override void LoadComplete() syncingColours = true; comboColours.Colours.Clear(); - comboColours.Colours.AddRange(Beatmap.BeatmapSkin?.ComboColours); + comboColours.Colours.AddRange(Beatmap.BeatmapSkin?.ComboColours ?? []); syncingColours = false; }); diff --git a/osu.Game/Screens/OnlinePlay/Match/DrawableMatchRoom.cs b/osu.Game/Screens/OnlinePlay/Match/DrawableMatchRoom.cs index 0c993f4abf32..3ceaf187e26d 100644 --- a/osu.Game/Screens/OnlinePlay/Match/DrawableMatchRoom.cs +++ b/osu.Game/Screens/OnlinePlay/Match/DrawableMatchRoom.cs @@ -3,6 +3,7 @@ using System; using System.ComponentModel; +using System.Diagnostics; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -38,6 +39,10 @@ public DrawableMatchRoom(Room room, bool allowEdit = true) { this.allowEdit = allowEdit; + // Roslyn sees required non-nullable property as nullable in constructor, + // as it can't see the implementation provides a fallback. + Debug.Assert(SelectedItem != null); + base.SelectedItem.BindTo(SelectedItem); } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 1c431b1cd484..e30ef761cde9 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -994,7 +994,7 @@ private void bindBindables() selectedMods.BindValueChanged(_ => { - if (decoupledRuleset.Value.Equals(rulesetNoDebounce)) + if (decoupledRuleset.Value?.Equals(rulesetNoDebounce) ?? false) advancedStats.Mods.Value = selectedMods.Value; }, true);