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

Wrong Collection initializer #3091

Closed
Solaestas opened this issue Oct 1, 2023 · 4 comments
Closed

Wrong Collection initializer #3091

Solaestas opened this issue Oct 1, 2023 · 4 comments
Labels
Bug Decompiler The decompiler engine itself

Comments

@Solaestas
Copy link

Input code

public class Test
{
	public static Test Create()
	{
		var ins = new Test();
		ins.Add(2);
		ins.Add(2);
		return ins;
	}
}

public static class TestExtension
{
	public static void Add(this Test obj, int value) { }
}

Erroneous output

public class Test
{
	public static Test Create()
	{
		return new Test { 2, 2 };
	}
}

public static class TestExtension
{
	public static void Add(this Test obj, int value)
	{
	}
}

Language version is C# 10.0 / VS2022
Collection initializer requires its type 'type' to implement System.Collections.IEnumerable.

Details

  • Product in use: VS extension
  • Version in use: 8.1.1.7464
@Solaestas Solaestas added Bug Decompiler The decompiler engine itself labels Oct 1, 2023
@siegfriedpammer
Copy link
Member

This is one is funny, because we already check for exactly that:

if (!targetType.GetAllBaseTypes().Any(i => i.IsKnownType(KnownTypeCode.IEnumerable) || i.IsKnownType(KnownTypeCode.IEnumerableOfT)))
return false;

@siegfriedpammer
Copy link
Member

Cannot reproduce

image

@Solaestas
Copy link
Author

I just found that it only happens on Release

@Solaestas
Copy link
Author

image

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 31, 2023
mattsh247 pushed a commit to mattsh247/ILSpy that referenced this issue Jul 30, 2024
…e checks in AccessPathElement.IsMethodApplicable.
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

2 participants