-
Notifications
You must be signed in to change notification settings - Fork 151
"Malformed contract section" when rewriting async methods #112
Comments
I can reproduce this issue. Will look at it more closely tomorrow. |
OK great! |
I can confirm that after commenting out contracts in the async methods above, Npgsql builds fine so this seems to be the last issue. |
Thanks a lot. Hope to push both fixes tomorrow. |
Thanks for the very quick help, looking forward to using CC in VS2015. |
Ok, minimum repo is: internal async Task WillFail(string str)
{
Contract.Requires(str != null);
await Task.Delay(42);
await Task.Delay(42);
} I.e. |
Ok, small update. The reason with this bug that Rosly compiler will generate following code: void IAsyncStateMachine.MoveNext()
{
int num = this.<>1__state;
try
{
TaskAwaiter taskAwaiter;
TaskAwaiter taskAwaiter2;
if (num != 0)
{
if (num == 1)
{
taskAwaiter = this.<>u__1;
this.<>u__1 = default(TaskAwaiter);
this.<>1__state = -1;
goto IL_E8;
}
Contract.Requires(this.str != null);
taskAwaiter2 = Task.Delay(42).GetAwaiter();
if (!taskAwaiter2.IsCompleted)
{
this.<>1__state = 0;
this.<>u__1 = taskAwaiter2;
Foo.<Method>d__0 <Method>d__ = this;
this.<>t__builder.AwaitUnsafeOnCompleted<TaskAwaiter, Foo.<Method>d__0>(ref taskAwaiter2, ref <Method>d__);
return;
}
}
else
{
taskAwaiter2 = this.<>u__1;
this.<>u__1 = default(TaskAwaiter);
this.<>1__state = -1;
}
taskAwaiter2.GetResult();
taskAwaiter2 = default(TaskAwaiter);
taskAwaiter = Task.Delay(42).GetAwaiter();
if (!taskAwaiter.IsCompleted)
{
this.<>1__state = 1;
this.<>u__1 = taskAwaiter;
Foo.<Method>d__0 <Method>d__ = this;
this.<>t__builder.AwaitUnsafeOnCompleted<TaskAwaiter, Foo.<Method>d__0>(ref taskAwaiter, ref <Method>d__);
return;
}
IL_E8:
taskAwaiter.GetResult();
taskAwaiter = default(TaskAwaiter);
}
catch (Exception exception)
{
this.<>1__state = -2;
this.<>t__builder.SetException(exception);
return;
}
this.<>1__state = -2;
this.<>t__builder.SetResult();
} I.e. |
@roji As a super nasty workaround could you try to add It seems that the only case when ccrewrite will fail, is when you have exactly two P.S. I'm working on the solution. This is just an experiment! |
Am unfortunately out... I'll try it out tomorrow morning if you haven't Am Freitag, 10. Juli 2015 schrieb Sergey Teplyakov :
|
@roji Sounds good! |
Fix is ready. Stay tuned! |
…ments. This fix resolves the issue microsoft#112. Now ccrewrite will recognize new pattern that roslyn-based compiler will use for async methods with 2 await statements.
Fixed by #114. |
Just to say that the new release of CC fixes the issues I ran into with Npgsql, thanks for the speedy work! |
Feel free to post any issues you have with vs2015, or even with older version! |
Encountered while building Npgsql:
Note that the files and line numbers are bogus: these async methods are in GeneratedAsync.cs (there's some code generation going on). In any case, the first methods is simply this:
Am not sure what is causing this: a simple async method with
Contract.Requires
seems OK...The text was updated successfully, but these errors were encountered: