-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
4 - In ReviewA fix for the issue is submitted for review.A fix for the issue is submitted for review.Area-Compilers
Milestone
Description
From Neal (in #26027):
I think both the spec and design notes are clear about the language intent: default is typeless and gets a type on conversion.
[Fact]
public void AssignmentToInt()
{
string source = @"
class C
{
static void Main()
{
int x = default;
System.Console.Write(x);
}
}
";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular7_1, options: TestOptions.DebugExe);
...
var tree = comp.SyntaxTrees.First();
var model = comp.GetSemanticModel(tree);
var nodes = tree.GetCompilationUnitRoot().DescendantNodes();
var def = nodes.OfType<LiteralExpressionSyntax>().Single();
Assert.Equal("System.Int32", model.GetTypeInfo(def).Type.ToTestDisplayString()); // should be null
Assert.Equal("System.Int32", model.GetTypeInfo(def).ConvertedType.ToTestDisplayString());
...
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
4 - In ReviewA fix for the issue is submitted for review.A fix for the issue is submitted for review.Area-Compilers