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

Const string reference replaced by string literal value #3222

Open
Aussiemon opened this issue Jun 14, 2024 · 1 comment
Open

Const string reference replaced by string literal value #3222

Aussiemon opened this issue Jun 14, 2024 · 1 comment
Labels
Decompiler The decompiler engine itself Enhancement Areas for improvement

Comments

@Aussiemon
Copy link

Aussiemon commented Jun 14, 2024

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 Aussiemon added Bug Decompiler The decompiler engine itself labels Jun 14, 2024
@Aussiemon Aussiemon changed the title Const string value replaced by string literal Const string reference replaced by string literal value Jun 14, 2024
@siegfriedpammer
Copy link
Member

siegfriedpammer commented Aug 18, 2024

This is not a bug, but a request for improvement. While we do some prettifying of double and float constants, that can be expressed as fractions or multiples of Math.PI or E, I don't think this case is worth the effort.

Questions:

  1. Where should we look for constants? Current type, current assembly or all referenced assemblies?
  2. Should we look at possible sub strings?

These two questions are examples of why such a feature is problematic in my opinion.

@siegfriedpammer siegfriedpammer added Enhancement Areas for improvement and removed Bug labels Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Decompiler The decompiler engine itself Enhancement Areas for improvement
Projects
None yet
Development

No branches or pull requests

2 participants