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

Missing variable declarations in repeated nested for-loops #3272

Closed
mmusu3 opened this issue Aug 27, 2024 · 3 comments
Closed

Missing variable declarations in repeated nested for-loops #3272

mmusu3 opened this issue Aug 27, 2024 · 3 comments
Labels
Bug Decompiler The decompiler engine itself

Comments

@mmusu3
Copy link

mmusu3 commented Aug 27, 2024

Input code

class NestedForLoopTest
{
    static void Test(int sizeX, int sizeY, int[] array)
    {
        for (int y = 0; y < sizeY; y++)
        {
            for (int x = 0; x < sizeX; x++)
                array[y * sizeX + x] = 0;
        }

        for (int y = 0; y < sizeY; y++)
        {
            for (int x = 0; x < sizeX; x++)
                array[y * sizeX + x] = 1;
        }
    }
}

Erroneous output

internal class NestedForLoopTest
{
	private static void Test(int sizeX, int sizeY, int[] array)
	{
		for (int y = 0; y < sizeY; y++)
		{
			for (int x = 0; x < sizeX; x++)
			{
				array[y * sizeX + x] = 0;
			}
		}
		for (int i = 0; i < sizeY; i++)
		{
			// Missing variable declaration
			for (i = 0; i < sizeX; i++)
			{
				array[i * sizeX + i] = 1;
			}
		}
	}
}

Details

Tested with version at commit 6a84a81

@mmusu3 mmusu3 added Bug Decompiler The decompiler engine itself labels Aug 27, 2024
@mmusu3

This comment has been minimized.

@greenozon
Copy link

I guess the nested loop should not re-use the i var
but instead introduce a new one?

@mmusu3
Copy link
Author

mmusu3 commented Sep 13, 2024

This is a regression from previous versions. I believe it was introduced in #3243

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Decompiler The decompiler engine itself
Projects
None yet
Development

No branches or pull requests

3 participants
@greenozon @mmusu3 and others