Fix #4019: Recognize with expressions whose initializer awaits

Roslyn spills the receiver of an initializer assignment that precedes an
await into a hoisted temporary, so the clone of a with expression (and the
object of an object initializer) reaches the initializer transform through
a copy it rejects. Only copies between two hoisted compiler temporaries are
inlined: folding copies of hoisted user locals as well would turn a user's
local into an initializer.
This commit is contained in:
dualfroz committed 2026-10-10 17:52:06 +02:00
1 parent ef47a24511
commit 85285c1cea
4 files changed
+50 -4

No files matched your search

@@ -3,6 +3,7 @@ using System;
using System.Runtime.InteropServices;
using System.Text;
#endif
using System.Threading.Tasks;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
@@ -129,6 +130,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
};
}
public async Task<PrimaryCtor> WithAwait(PrimaryCtor input)
{
return input with {
A = await Task.FromResult(42)
};
}
public async Task<Fields> WithAwaitAfterConstant(Fields input)
{
return input with {
A = 42,
B = await Task.FromResult(3.141)
};
}
}
public abstract record WithNestedRecords