-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersResolution-By DesignThe behavior reported in the issue matches the current designThe behavior reported in the issue matches the current design
Description
Version Used:
C# 7.3
Excerpt from Visual Studio About dialog (items suspected to be relevant)
Microsoft Visual Studio Enterprise 2017
Version 15.9.2
VisualStudio.15.Release/15.9.2+28307.108
Microsoft .NET Framework
Version 4.7.03056
C# Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Steps to Reproduce:
- given the following example:
var place = new
{
Metadata = (IDictionary<string, string>)null
};
// ...
var sb = new StringBuilder();
// ...
if(place.Metadata?.TryGetValue("erpid", out var erpid) ?? false)
{
sb.Append(" | ");
sb.Append("erpid=");
sb.Append(erpid);
}where Metadata is IDictionary<string,string> typed nullable member of place.
Expected Behavior:
erpid is initialized in the scope, as the expression can be evaluated at compile time to determine that the erpid variable will be initialized in the scope.
Example code compiles correctly.
Actual Behavior:
Null-safe navigation and null-coalescing break the out variable initialization detection.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersResolution-By DesignThe behavior reported in the issue matches the current designThe behavior reported in the issue matches the current design
