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

Bug in control flow analysis for out arguments (VS 16.8, .NET 5) #3431

Open
rameel opened this issue Feb 11, 2019 · 3 comments
Open

Bug in control flow analysis for out arguments (VS 16.8, .NET 5) #3431

rameel opened this issue Feb 11, 2019 · 3 comments
Assignees
Labels
Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification Proposal champion
Milestone

Comments

@rameel
Copy link

rameel commented Feb 11, 2019

Looks like the C# compiler have a bug in control flow analysis

// Project1.csproj
using Library;

namespace ControlFlowError
{
    public sealed class ValueProvider
    {
        public bool TryGetValue(out Result result)
        {
            // Expected: The out parameter 'result' must be assigned to before control leaves the current method
            return false;
        }
    }
}
// Project2.csproj
namespace Library
{
    public readonly struct Result
    {
        public object Value { get; }

        //public readonly object Value; // 2. Works as expected
        //public readonly int Value;    // 3. Works as expected
    }
}

Steps to Reproduce:
Clone the project https://github.com/rameel/ControlFlowError

Expected Behavior:
Compilation error with the message: The out parameter 'result' must be assigned to before control leaves the current method

Actual Behavior:
Compiled successfully

@rameel rameel changed the title Control flow analysis for out arguments Bug in control flow analysis for out arguments Feb 11, 2019
@gafter gafter self-assigned this Mar 26, 2019
@gafter
Copy link
Member

gafter commented Mar 26, 2019

This is by design (the struct has no accessible fields), but I believe we want to change the design.

@rameel
Copy link
Author

rameel commented Mar 26, 2019

Ah, got it

@gafter gafter transferred this issue from dotnet/roslyn May 6, 2020
@gafter gafter added this to TRIAGE NEEDED in Language Version Planning May 6, 2020
@gafter
Copy link
Member

gafter commented May 9, 2020

Also reported at dotnet/roslyn#39062 and many other places.

@333fred 333fred moved this from TRIAGE NEEDED to 9.0 Candidate in Language Version Planning Jul 13, 2020
@333fred 333fred added this to the 9.0 candidate milestone Jul 13, 2020
@jcouv jcouv changed the title Bug in control flow analysis for out arguments Bug in control flow analysis for out arguments (VS 16.8, .NET 5) Sep 1, 2020
@MadsTorgersen MadsTorgersen modified the milestones: 9.0 candidate, 9.0 Sep 9, 2020
@333fred 333fred added the Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification label Oct 16, 2020
@333fred 333fred removed this from 9.0 Candidate in Language Version Planning Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification Proposal champion
Projects
None yet
Development

No branches or pull requests

4 participants