Skip to content

Another overlooked detail in the primary constructor's decision process #3621

Description

@sonyps5201314

Input code

    record WebPair7(string name, string? value, ref readonly object encode)
    {
        public string? Value { get; } = name;
        public string Name { get; } = value;
        string? WebValue { get; } = name != null ? "111" : value;
        string? WebValue2;
    }

Erroneous output

// TestClassPropertyInit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// TestClassPropertyInit.WebPair7
using System.Runtime.CompilerServices;

internal record WebPair7
{
	public string name { get; init; }

	public string? value { get; init; }

	public object encode { get; init; }

	public string? Value { get; }

	public string Name { get; }

	private string? WebValue { get; }

	private string? WebValue2;

	public WebPair7(string name, string? value, ref readonly object encode)
	{
		this.name = name;
		this.value = value;
		this.encode = encode;
		Value = name;
		Name = value;
		WebValue = ((name != null) ? "111" : value);
		base..ctor();
	}

	[CompilerGenerated]
	public void Deconstruct(out string name, out string? value, out object encode)
	{
		name = this.name;
		value = this.value;
		encode = this.encode;
	}
}

The line base..ctor(); appeared.

Details

This commit in my original PR actually included this example and provided a fix, but it seems you might have overlooked it. Based on my local testing, even after your recent 10+ revisions regarding primary constructors, the current implementation is still not as robust as what was in my original PR.

Therefore, I strongly recommend once again that you review the individual commit history of my PR. There are many details in my code that you haven't captured yet, which I have also explained multiple times in previous GitHub Issue comments.

Thank you. Perhaps it is not my place to offer advice, and I realize this might be hard to accept emotionally, but I simply wish for ILSpy to be as perfect as possible.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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