Skip to content

Variable naming doesn't find all accessible types with lower case names #3571

@ds5678

Description

@ds5678

Input code

using System;
using System.Runtime.InteropServices;

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
	internal static class Issue4000
	{
		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public readonly struct fsResult
		{
			public static fsResult Success => default(fsResult);
			public static fsResult Failure => default(fsResult);
			public bool Succeeded => true;
			public bool Failed => false;
			public static fsResult operator +(fsResult a, fsResult b)
			{
				return default(fsResult);
			}
		}

		public static fsResult M()
		{
			fsResult success = fsResult.Success;
			fsResult fsResult2 = success + fsResult.Success;
			if (fsResult2.Succeeded)
			{
				return success;
			}
			Console.WriteLine("Failed");
			return fsResult2 + fsResult.Failure;
		}
	}
}

Erroneous output

using System;
using System.Runtime.InteropServices;

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
	internal static class Issue4000
	{
		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public readonly struct fsResult
		{
			public static fsResult Success => default(fsResult);
			public static fsResult Failure => default(fsResult);
			public bool Succeeded => true;
			public bool Failed => false;
			public static fsResult operator +(fsResult a, fsResult b)
			{
				return default(fsResult);
			}
		}

		public static fsResult M()
		{
			fsResult success = fsResult.Success;
			fsResult fsResult = success + fsResult.Success;
			if (fsResult.Succeeded)
			{
				return success;
			}
			Console.WriteLine("Failed");
			return fsResult + fsResult.Failure;
		}
	}
}
CS0841: Cannot use local variable 'fsResult' before it is declared

Details

  • Product in use: ILSpy
  • Version in use: 61f82d0
  • Any other relevant information to the issue, or your interest in contributing a fix.
    • I've implemented a fix in AssignVariableNames and am polishing it up for a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDecompilerThe decompiler engine itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions