Repository: dotnet/roslyn
File: src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs (C#)

Code before:
            return Feature(CodeAnalysis.Feature.RunNullableAnalysis) switch
            {
                "always" => true,
                "never" => false,
                _ => null,
            };
        }

        /// <summary>
        /// Returns true if this method should be processed with runtime async handling instead
        /// of compiler async state machine generation.
        /// </summary>
        internal bool IsRuntimeAsyncEnabledIn(Symbol? symbol)
        {
            if (!Assembly.RuntimeSupportsAsyncMethods)
            {
                return false;
            }

            if (symbol is not MethodSymbol method)
            {
                return false;
            }

            Debug.Assert(ReferenceEquals(method.ContainingAssembly, Assembly));

            var methodReturn = method.ReturnType.OriginalDefinition;
            if (((InternalSpecialType)methodReturn.ExtendedSpecialType) is not (
                    InternalSpecialType.System_Threading_Tasks_Task or
                    InternalSpecialType.System_Threading_Tasks_Task_T or
                    InternalSpecialType.System_Threading_Tasks_ValueTask or
                    InternalSpecialType.System_Threading_Tasks_ValueTask_T))
            {
                return false;
            }

            return symbol switch
            {
                SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: ThreeState.True } => true,
                SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: ThreeState.False } => false,
                _ => Feature(CodeAnalysis.Feature.RuntimeAsync) == "on"
            };
        }

        /// <summary>
        /// The language version that was used to parse the syntax trees of this compilation.
        /// </summary>
        public LanguageVersion LanguageVersion
        {
            get;
        }

Review comment (bug):
>Debug.Assert(method.IsDefinition); [](http://example.com/codeflow?start=12&length=34)

Is it expected that this method will be called for non-definition non-method?

Code after:
            return Feature(CodeAnalysis.Feature.RunNullableAnalysis) switch
            {
                "always" => true,
                "never" => false,
                _ => null,
            };
        }

        /// <summary>
        /// Returns true if this method should be processed with runtime async handling instead
        /// of compiler async state machine generation.
        /// </summary>
        internal bool IsRuntimeAsyncEnabledIn(Symbol? symbol)
        {
            if (!Assembly.RuntimeSupportsAsyncMethods)
            {
                return false;
            }

            if (symbol is not MethodSymbol { IsAsync: true } method)
            {
                return false;
            }

            Debug.Assert(ReferenceEquals(method.ContainingAssembly, Assembly));
            Debug.Assert(method.IsDefinition);

            var runtimeAsyncEnabledInMethod = symbol switch
            {
                SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: ThreeState.True } => true,
                SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: ThreeState.False } => false,
                _ => Feature(CodeAnalysis.Feature.RuntimeAsync) == "on"
            };

            if (!runtimeAsyncEnabledInMethod)
            {
                return false;
            }

            var methodReturn = method.ReturnType.OriginalDefinition;
            if ((object)methodReturn == LambdaSymbol.ReturnTypeIsBeingInferred)
            {
                // During lambda return type inference we have not yet established whether
                // the return type is Task/ValueTask, so we assume runtime async to allow
                // caching to be used for the majority case when the return type is indeed
                // Task/ValueTask-based. If the return type ends up not being Task/ValueTask,
                // that will bust the cache and ensure the body is re-bound with the correct
                // handling
                return true;
            }