
BUG OF THE MONTH | Assignment to Variable without Use
private void Draw(Rect windowRect)
{
var rect = new Rect(....);
....
if (m_NumFilteredVariants > 0)
{
....
if (m_NumFilteredVariants > maxFilteredLength)
{
GUI.Label(....);
rect.y += rect.height;
}
}
else
{
GUI.Label(rect, "No variants with these keywords");
rect.y += rect.height; // <=
}
rect.y = windowRect.height - kMargin - kSpaceHeight –
EditorGUI.kSingleLineHeight; // <=
....
}
V3008 The ‘rect.y’ variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 370, 366. ShaderVariantCollectionInspector.cs 370
The analyzer reports that the same variable — rect.y — is assigned a value twice and the code does not use the variable between the assignments. If we take a closer look, we’ll see that the value for this variable is produced a bit higher in the code, under the m_NumFilteredVariants > maxFilteredLength condition — and is also lost.
Consequently, all variable value changes, except for the last one, make no sense.