Skip to content

Compiler crashes on local method opted into runtime async #82397

@jkotas

Description

@jkotas

Net 11 Preview 1

Steps to Reproduce:

  1. dotnet new console
  2. Copy & paste program program below
  3. dotnet build

A minimal repro, with source-code provided, is ideal. Most compiler/language issues can be distilled into a snippet that can be pasted into .NET Lab.

Expected Behavior: Compiles

Actual Behavior: Compiler crash (NullReferenceException in Microsoft.CodeAnalysis.CSharp.AsyncMethodToStateMachineRewriter.VisitAwaitExpression)

using System;

Task.Run(async () =>
{
   await Func();

   [System.Runtime.CompilerServices.RuntimeAsyncMethodGeneration(true)]
   static async Task Func()
   {
       await Task.Delay(1);
       await Task.Yield();
   }
});

namespace System.Runtime.CompilerServices
{
    [AttributeUsage(AttributeTargets.Method)]
    internal class RuntimeAsyncMethodGenerationAttribute(bool runtimeAsync) : Attribute
    {
        public bool RuntimeAsync { get; } = runtimeAsync;
    }
}

Encountered in dotnet/runtime#123727

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions