ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

lambda parameter name conflicts with name from outer scope

Open chucklu opened this issue 4 years ago • 4 comments

Try to decompile the following exe file Hearthbuddy-20190802-002.zip

// Triton.Common.TypeLoader<T>.Class236
internal IEnumerable<Type> method_1(Assembly assembly_0)
{
	return from type_0 in assembly_0.GetTypes()
		where !type_0.IsAbstract && (type_0.IsSubclassOf(typeof(T)) || type_0.GetInterfaces().Any((Type type_0) => type_0 == typeof(T)))
		select type_0;
}

chucklu avatar Mar 16 '20 11:03 chucklu

By the way, I am using ILSpy_binaries_6.0.0.5559-preview2.

chucklu avatar Mar 16 '20 11:03 chucklu

The DnSpy decompile the above code as

internal IEnumerable<Type> method_1(Assembly assembly_0)
			{
				return assembly_0.GetTypes().Where(new Func<Type, bool>(TypeLoader<T>.Class236.<>9.method_2));
			}

			// Token: 0x0600161C RID: 5660 RVA: 0x000D06D0 File Offset: 0x000CE8D0
			internal bool method_2(Type type_0)
			{
				if (type_0.IsAbstract)
				{
					return false;
				}
				if (!type_0.IsSubclassOf(typeof(T)))
				{
					return type_0.GetInterfaces().Any(new Func<Type, bool>(TypeLoader<T>.Class236.<>9.method_3));
				}
				return true;
			}

internal bool method_3(Type type_0)
			{
				return type_0 == typeof(T);
			}

chucklu avatar Mar 16 '20 11:03 chucklu

See also #1572

siegfriedpammer avatar Apr 02 '20 11:04 siegfriedpammer

Note that C# 8 started allowing shadowing of lambda parameters. So if we start renaming parameters to avoid this issue, we should restrict that to C# <= 7.3.

dgrunwald avatar Jul 16 '20 21:07 dgrunwald