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.
A
withexpression whose initializer contains anawaitis not recognized: the compiler-generated<Clone>$call survives into the output under its escaped name.Input
Actual output
_003CClone_003E_0024is the escaped<Clone>$; the output does not compile.Expected output
Notes
The
awaitis what defeats it - the samewithexpression 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.