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:
1 parent
ef47a24511
commit
85285c1cea
4 files changed
+50
-4
No files matched your search
@@ -16,9 +16,9 @@
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// Await shapes that still decompile to code that does not compile are tracked as #4017 (type
|
||||
// parameter with an interface constraint), #4018 (static dynamic call) and #4019 (with
|
||||
// expression); they are absent here because they have no correct output to pin yet.
|
||||
// An await shape that still decompiles to code that does not compile is tracked as #4017 (type
|
||||
// parameter with an interface constraint); it is absent here because it has no correct output to
|
||||
// pin yet.
|
||||
|
||||
#pragma warning disable 1998
|
||||
using System;
|
||||
|
||||
@@ -22,6 +22,9 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
#if ROSLYN2
|
||||
using System.Threading.Tasks;
|
||||
#endif
|
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
|
||||
{
|
||||
@@ -1233,6 +1236,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
|
||||
Property = 42
|
||||
};
|
||||
}
|
||||
|
||||
#if ROSLYN2
|
||||
public static async Task<C> ObjectInitializerWithAwait(Task<int> task)
|
||||
{
|
||||
return new C {
|
||||
Z = await task
|
||||
};
|
||||
}
|
||||
|
||||
public static async Task<C> ObjectInitializerWithAwaitAfterConstant(Task<S> task)
|
||||
{
|
||||
return new C {
|
||||
Z = 42,
|
||||
Y = await task
|
||||
};
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region Collection initializer
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user