Skip to content

with expression containing an await leaves the raw <Clone>$ call in the output #4019

Description

@christophwille

A with expression whose initializer contains an await is not recognized: the compiler-generated <Clone>$ call survives into the output under its escaped name.

Input

public record Record(int X);

private static Task<int> Get()
{
	return Task.FromResult(1);
}

public async Task<Record> WithExpressionContainingAwait(Record value)
{
	return value with {
		X = await Get()
	};
}

Actual output

public async Task<Record> WithExpressionContainingAwait(Record value)
{
	Record record = value._003CClone_003E_0024();
	Record record2 = record;
	record2.X = await Get();
	return record;
}

_003CClone_003E_0024 is the escaped <Clone>$; the output does not compile.

Expected output

public async Task<Record> WithExpressionContainingAwait(Record value)
{
	return value with {
		X = await Get()
	};
}

Notes

The await is what defeats it - the same with expression round-trips when the initializer has no suspension point. The state-machine split puts the clone call and the property assignment in different blocks, so the transform that recognizes the with-expression pattern no longer sees them adjacent.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions