ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

Const string reference replaced by string literal value

Open Aussiemon opened this issue 2 months ago • 1 comments

Similar to #1084.

The reference to const kPlantableNameKey is replaced by its value in the constructor, which is valid code, but an unused assignment / variable warning at the IDE. Perhaps the decompiler could check for private constants and replace matching literals in scope, or perhaps this is a more specific edge case.

Input code

public class TestDecomp
{
	private const string kPlantableNameKey = "Chamomile";

	public string GetPlantableNameKey()
	{
		return kPlantableNameKey;
	}
}

Erroneous output (from .NET 8.0 SDK class library)

public class TestDecomp
{
	private const string kPlantableNameKey = "Chamomile";

	public string GetPlantableNameKey()
	{
		return "Chamomile";
	}
}

Details

  • Product in use: ILSpy
  • Version in use: ILSpy 9.0 Preview 2

Aussiemon avatar Jun 14 '24 19:06 Aussiemon