1
Vote

Rule Idea: flag compiler bug with named optional out arguments

description

http://connect.microsoft.com/VisualStudio/feedback/details/716017/evaluation-of-named-by-ref-arguments-in-c
 
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/6a8b6fbf-43b9-4f19-934b-695053b7d60d?prof=required
 
namespace WindowsFormsApplication8
{
public partial class Form1 : System.Windows.Forms.Form
{
    public Form1()
    {
        this.InitializeComponent();
    }
 
    protected override void OnLoad(System.EventArgs e)
    {
        base.OnLoad(e);
 
        try
        {
            var info = new Info();
 

if true

            // This call works.
            this.Foo(out info._dictionary);

else

            // This call does not work.
            this.Foo(result: out info._dictionary);

endif

 
            if (info._dictionary == null)
            {
                throw new System.Exception("Dictionary is null.");
            }
        }
        catch (System.Exception exception)
        {
            System.Windows.Forms.MessageBox.Show(exception.Message);
        }
    }
 
    private void Foo(out System.Collections.Generic.Dictionary<string, string> result)
    {
        result = new System.Collections.Generic.Dictionary<string, string>();
    }
 
    private struct Info
    {
        public System.Collections.Generic.Dictionary<string, string> _dictionary;
    }
}
}

comments