JetBrains / JetBrains/resharper-unity

[Range] and [Min] attributes are considered hard limits

Open
#2,187 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.2k
Forks
142
PR merge metrics
No merged PRs in 30d

Description

Consider the following snippet:

using UnityEngine;

public class RiderTest : MonoBehaviour {

[Min(1)] public int SmallNumber = 1;
[Range(1, 2)] public int BigNumber = 1;

void Start() {
SmallNumber -= 1;
if (SmallNumber <= 0) Debug.Log("this limit only applies in the editor!");

BigNumber += 1;
if (BigNumber <= 0) Debug.Log("this limit only applies in the editor!");
if (BigNumber > 2) Debug.Log("this limit only applies in the editor!");
}
}

As the comparison lies outside the `[Min]` and `[Range]` attributes Rider will flag the conditionals as "Expression is always false", however, those limitations only apply in the editor. Not for runtime code.

This information _is_ useful, but should perhaps not quite be a warning.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.