This project is read-only.
2

Resolved

"Use of unassigned local variable" when using declaration expressions in object initializer braces

description

using System.Collections.Generic;
          
public class MyClass {
    public void MyMethod() {
        new Dictionary<string, object> { 
            [(string x = "a")] = x
        };
    }
}
Expected:
Either reference to x on right hand-side is not allowed altogether, or the reference uses "a".

Actual:
error CS0165: Use of unassigned local variable 'x'

Link:
http://tryroslyn.azurewebsites.net/#K4Zwlgdg5gBAygTxAFwKYFsB0BhA9gG31QGNkxcIRMBxVCVAJzGIG4AoGTr7tgB2ABG+ZjGL4AhiBAwAsgmwSpMAN4cu/ISIBuuMABNZCGamQALXHoAUAShVrunegHcYAEWZkK4hggA8KJmgAGhhcAQArEmQAPhUYewduAG1LAMhYAA8YAF4YACJxPOsAXRyYDITuAF92arYqoAA