-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Prototype for "default": semantic model, constant value and more tests #16425
Changes from all commits
4dc80f1
79effee
89b5d07
28dba9e
79353be
af7bb3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -553,7 +553,7 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, Diagnostic | |
return BindDefaultExpression((DefaultExpressionSyntax)node, diagnostics); | ||
|
||
case SyntaxKind.DefaultLiteral: | ||
return new BoundDefaultOperator((DefaultLiteralSyntax)node); | ||
return BindDefaultLiteral((DefaultLiteralSyntax)node); | ||
|
||
case SyntaxKind.TypeOfExpression: | ||
return BindTypeOf((TypeOfExpressionSyntax)node, diagnostics); | ||
|
@@ -656,6 +656,11 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, Diagnostic | |
} | ||
} | ||
|
||
private static BoundExpression BindDefaultLiteral(DefaultLiteralSyntax node) | ||
{ | ||
return new BoundDefaultLiteral(node, ConstantValue.DefaultLiteral, type: null); | ||
} | ||
|
||
private BoundExpression BindTupleExpression(TupleExpressionSyntax node, DiagnosticBag diagnostics) | ||
{ | ||
SeparatedSyntaxList<ArgumentSyntax> arguments = node.Arguments; | ||
|
@@ -970,7 +975,7 @@ internal static ConstantValue GetConstantSizeOf(TypeSymbol type) | |
private BoundExpression BindDefaultExpression(DefaultExpressionSyntax node, DiagnosticBag diagnostics) | ||
{ | ||
TypeSymbol type = this.BindType(node.Type, diagnostics); | ||
return new BoundDefaultOperator(node, type); | ||
return new BoundDefaultLiteral(node, type); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -1730,8 +1735,6 @@ private void GenerateExplicitConversionErrors( | |
return; | ||
} | ||
|
||
// PROTOTYPE(default) SHould handle default literal here? | ||
|
||
if (conversion.ResultKind == LookupResultKind.OverloadResolutionFailure) | ||
{ | ||
Debug.Assert(conversion.IsUserDefined); | ||
|
@@ -4834,7 +4837,6 @@ private BoundExpression BindMemberAccessWithBoundLeft( | |
return BadExpression(node, boundLeft); | ||
} | ||
|
||
// PROTOTYPE(default) unify with case above | ||
// No member accesses on default | ||
if (boundLeft.IsLiteralDefault()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if these two cases (default and unbound lambda) can be combined by testingfor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I addressed your other feedback in latest commit, but I couldn't quite see how to factor as you suggested here. |
||
{ | ||
|
@@ -5011,7 +5013,7 @@ private BoundExpression BindMemberAccessWithBoundLeft( | |
|
||
private static void WarnOnAccessOfOffDefault(SyntaxNode node, BoundExpression boundLeft, DiagnosticBag diagnostics) | ||
{ | ||
if (boundLeft != null && boundLeft.Kind == BoundKind.DefaultOperator && boundLeft.ConstantValue == ConstantValue.Null) | ||
if (boundLeft != null && boundLeft.Kind == BoundKind.DefaultLiteral && boundLeft.ConstantValue == ConstantValue.Null) | ||
{ | ||
Error(diagnostics, ErrorCode.WRN_DotOnDefault, node, boundLeft.Type); | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
(T)default
a constant? Isconst object o = (T)default;
legal?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check. I have a test for
int x = (short)default;
(legal), but not with a generic cast.My expectation is that
(T)default
should behave the same asdefault(T)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about scenarios when it is of type user-defined struct? Is it supposed to have constant value then?