Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Failed to emit module' error when compiling usages of a nested tasklike type #16493

Closed
TessenR opened this issue Jan 13, 2017 · 5 comments
Closed
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug New Language Feature - ValueTask ValueTask _Product-level triaged Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@TessenR
Copy link

TessenR commented Jan 13, 2017

Roslyn doesn't detect errors in the following code snippet but is unable to compile it. Fails with 'failed to emit module' error in VS2017 RC.

public class Program
{
    public static void Main() { }
}

public class TypeParametersProvider<T>
{
    public async ValueTask Method()
    {
        await Task.Delay(5);
        return;
    }

    [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder))]
    public struct ValueTask
    {
    }
}

public class AsyncValueTaskMethodBuilder
{
    public TypeParametersProvider<int>.ValueTask Task { get => default(TypeParametersProvider<int>.ValueTask); }
    public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine { }
    public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine { }
    public static AsyncValueTaskMethodBuilder Create() { return default(AsyncValueTaskMethodBuilder); }
    public void SetException(Exception exception) { }
    public void SetResult() { }
    public void SetStateMachine(IAsyncStateMachine stateMachine) { }
    public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { }
}

namespace System.Runtime.CompilerServices
{
    public class AsyncMethodBuilderAttribute : System.Attribute
    {
        public AsyncMethodBuilderAttribute(Type type) { }
    }
}
@jcouv
Copy link
Member

jcouv commented Jan 15, 2017

This repros on latest master (TryRoslyn).

@jcouv jcouv assigned jcouv and unassigned AlekseyTs Jan 15, 2017
@jcouv
Copy link
Member

jcouv commented Jan 15, 2017

@cston, I couldn't find a feature doc for task-like, so I went back to the feature proposal. From my understanding, TypeParametersProvider<T>.ValueTask cannot be "task-like" because it is neither (1) a concrete type nor (2) a generic type of arity 1.
Can you confirm?
If that is correct, I'm assuming we should just expect an error in the above scenario.

@jcouv
Copy link
Member

jcouv commented Jan 16, 2017

It looks like my thinking was wrong. There are tests with task-like types nested in generic types, so this is supported.
Looking at this more, it looks like the problem is the mismatch between the return type of Method (returns TypeParametersProvider<T>.ValueTask) and the type created by the AsyncMethodBuilder (creates a TypeParametersProvider<int>.ValueTask).

@jcouv jcouv added the 4 - In Review A fix for the issue is submitted for review. label Jan 16, 2017
@jcouv
Copy link
Member

jcouv commented Jan 19, 2017

@jcouv jcouv modified the milestones: 2.1, 2.0 (RTM) Jan 19, 2017
@jcouv
Copy link
Member

jcouv commented Jan 20, 2017

@TessenR Thanks for reporting this issue.
Fixed with #16530. Unfortunately, the fix won't make it into VS 2017 RTM. But it will ship in the first minor release after that.

@jcouv jcouv added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Jan 20, 2017
@jcouv jcouv closed this as completed Jan 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug New Language Feature - ValueTask ValueTask _Product-level triaged Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants