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 couple of new r# inspections #25552

Merged
merged 2 commits into from
Nov 24, 2023
Merged
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
13 changes: 4 additions & 9 deletions osu.Game/Beatmaps/Beatmap.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Objects;
Expand All @@ -26,8 +24,7 @@ public BeatmapDifficulty Difficulty
{
difficulty = value;

if (beatmapInfo != null)
beatmapInfo.Difficulty = difficulty.Clone();
beatmapInfo.Difficulty = difficulty.Clone();
}
}

Expand All @@ -40,8 +37,7 @@ public BeatmapInfo BeatmapInfo
{
beatmapInfo = value;

if (beatmapInfo?.Difficulty != null)
Difficulty = beatmapInfo.Difficulty.Clone();
Difficulty = beatmapInfo.Difficulty.Clone();
}
}

Expand Down Expand Up @@ -119,12 +115,11 @@ public double GetMostCommonBeatLength()
IBeatmap IBeatmap.Clone() => Clone();

public Beatmap<T> Clone() => (Beatmap<T>)MemberwiseClone();

public override string ToString() => BeatmapInfo.ToString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thing I find slightly disconcerting because there's this but there's also

if (beatmapInfo != null)
beatmapInfo.Difficulty = difficulty.Clone();

if (beatmapInfo?.Difficulty != null)
Difficulty = beatmapInfo.Difficulty.Clone();

What are these other nullchecks? How does r# even infer that this can never be null, on a file with disabled nullability annotations no less?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've enabled NRT and fixed those. It does seem to pass the test gauntlet at least.

}

public class Beatmap : Beatmap<HitObject>
{
public new Beatmap Clone() => (Beatmap)base.Clone();

public override string ToString() => BeatmapInfo?.ToString() ?? base.ToString();
}
}