Skip to content

Ref locals before C# 7 #3468

Open
Open
@ds5678

Description

@ds5678

Input code

public struct StructWithStringField
{
	public string Id;
	public static void ModifyArray(StructWithStringField[] array)
	{
		int num = 0;
		while (num < 10)
		{
			array[0].Id = (++num).ToString();
		}
	}
}

Erroneous output

public struct StructWithStringField
{
	public string Id;
	public static void ModifyArray(StructWithStringField[] array)
	{
		int num = 0;
		while (num < 10)
		{
			ref StructWithStringField reference = ref array[0];
			int num2 = ++num;
			reference.Id = num2.ToString();
		}
	}
 }

This produces an error before C# 7:

CS1525: Unexpected symbol 'ref'

Details

  • Product in use: pretty unit test
  • Version in use: latest commit (aff9649)
  • Any other relevant information to the issue, or your interest in contributing a fix.
    • I, of course, am willing to work on this.
    • I think I've seen other situations with similar ref local issues, but I don't have any examples at this time. I'm checking to see if I can find some.

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