Skip to content
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

Make "default" a literal and other tweaks from recent LDM #18213

Merged
merged 9 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ protected BoundExpression CreateConversion(
}

ConstantValue constantValue = this.FoldConstantConversion(syntax, source, conversion, destination, diagnostics);
if (conversion.Kind == ConversionKind.DefaultOrNullLiteral && source.Kind == BoundKind.DefaultLiteral)
if (conversion.Kind == ConversionKind.DefaultOrNullLiteral && source.Kind == BoundKind.DefaultExpression)
{
source = ((BoundDefaultLiteral)source).Update(constantValue, destination);
source = ((BoundDefaultExpression)source).Update(constantValue, destination);
}

return new BoundConversion(
Expand Down Expand Up @@ -904,7 +904,7 @@ public ConstantValue FoldConstantConversion(
var sourceConstantValue = source.ConstantValue;
if (sourceConstantValue == null)
{
if (conversion.Kind == ConversionKind.DefaultOrNullLiteral && source.Kind == BoundKind.DefaultLiteral)
if (conversion.Kind == ConversionKind.DefaultOrNullLiteral && source.Kind == BoundKind.DefaultExpression)
{
return destination.GetDefaultValue();
}
Expand Down
20 changes: 10 additions & 10 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, Diagnostic
case SyntaxKind.NullLiteralExpression:
return BindLiteralConstant((LiteralExpressionSyntax)node, diagnostics);

case SyntaxKind.DefaultLiteralExpression:
return BindDefaultLiteral(node);

case SyntaxKind.ParenthesizedExpression:
// Parenthesis tokens are ignored, and operand is bound in the context of parent
// expression.
Expand All @@ -552,9 +555,6 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, Diagnostic
case SyntaxKind.DefaultExpression:
return BindDefaultExpression((DefaultExpressionSyntax)node, diagnostics);

case SyntaxKind.DefaultLiteral:
return BindDefaultLiteral((DefaultLiteralSyntax)node);

case SyntaxKind.TypeOfExpression:
return BindTypeOf((TypeOfExpressionSyntax)node, diagnostics);

Expand Down Expand Up @@ -652,6 +652,11 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, Diagnostic
}
}

private static BoundExpression BindDefaultLiteral(ExpressionSyntax node)
{
return new BoundDefaultExpression(node, constantValueOpt: null, type: null);
}

private BoundExpression BindRefExpression(ExpressionSyntax node, DiagnosticBag diagnostics)
{
var firstToken = node.GetFirstToken();
Expand Down Expand Up @@ -773,11 +778,6 @@ private BoundExpression BindDeclarationVariables(TypeSymbol declType, VariableDe
}
}

private static BoundExpression BindDefaultLiteral(DefaultLiteralSyntax node)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private static BoundExpression BindDefaultLiteral(DefaultLiteralSyntax node) [](start = 8, length = 76)

I would keep this method.

{
return new BoundDefaultLiteral(node, constantValueOpt: null, type: null);
}

private BoundExpression BindTupleExpression(TupleExpressionSyntax node, DiagnosticBag diagnostics)
{
SeparatedSyntaxList<ArgumentSyntax> arguments = node.Arguments;
Expand Down Expand Up @@ -1062,7 +1062,7 @@ internal static ConstantValue GetConstantSizeOf(TypeSymbol type)
private BoundExpression BindDefaultExpression(DefaultExpressionSyntax node, DiagnosticBag diagnostics)
{
TypeSymbol type = this.BindType(node.Type, diagnostics);
return new BoundDefaultLiteral(node, type);
return new BoundDefaultExpression(node, type);
}

/// <summary>
Expand Down Expand Up @@ -5218,7 +5218,7 @@ private BoundExpression BindMemberAccessWithBoundLeft(

private static void WarnOnAccessOfOffDefault(SyntaxNode node, BoundExpression boundLeft, DiagnosticBag diagnostics)
{
if (boundLeft != null && boundLeft.Kind == BoundKind.DefaultLiteral && boundLeft.ConstantValue == ConstantValue.Null)
if (boundLeft != null && boundLeft.Kind == BoundKind.DefaultExpression && boundLeft.ConstantValue == ConstantValue.Null)
{
Error(diagnostics, ErrorCode.WRN_DotOnDefault, node, boundLeft.Type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private static bool ReportBadDynamicArguments(
}
else if (arg.IsLiteralDefault())
{
Error(diagnostics, ErrorCode.ERR_BadDynamicMethodArgDefault, arg.Syntax);
Error(diagnostics, ErrorCode.ERR_BadDynamicMethodArgDefaultLiteral, arg.Syntax);
hasErrors = true;
}
else
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3063,6 +3063,16 @@ private BoundExpression BindAsOperator(BinaryExpressionSyntax node, DiagnosticBa
return new BoundAsOperator(node, operand, typeExpression, Conversion.DefaultOrNullLiteral, resultType);
}

if (operand.IsLiteralDefault())
{
var defaultLiteral = (BoundDefaultExpression)operand;
Debug.Assert((object)defaultLiteral.Type == null);
Debug.Assert((object)defaultLiteral.ConstantValueOpt == null);

operand = new BoundDefaultExpression(defaultLiteral.Syntax, constantValueOpt: ConstantValue.Null,
type: GetSpecialType(SpecialType.System_Object, diagnostics, node));
}

if (operand.Kind == BoundKind.MethodGroup)
{
Error(diagnostics, ErrorCode.ERR_NoExplicitBuiltinConv, node, MessageID.IDS_MethodGroup.Localize(), targetType);
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ protected BoundCall MakeQueryInvocation(CSharpSyntaxNode node, BoundExpression r
}
else if (ultimateReceiver.IsLiteralDefault())
{
diagnostics.Add(ErrorCode.ERR_DefaultNotValid, node.Location);
diagnostics.Add(ErrorCode.ERR_DefaultLiteralNotValid, node.Location);
}
else if (ultimateReceiver.Kind == BoundKind.NamespaceExpression)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ private bool IsValidFixedVariableInitializer(TypeSymbol declType, SourceLocalSym
{
Debug.Assert(initializerOpt.Kind == BoundKind.Conversion &&
(((BoundConversion)initializerOpt).Operand.IsLiteralNull() ||
((BoundConversion)initializerOpt).Operand.Kind == BoundKind.DefaultLiteral),
((BoundConversion)initializerOpt).Operand.Kind == BoundKind.DefaultExpression),
"All other typeless expressions should have conversion errors");

// CONSIDER: this is a very confusing error message, but it's what Dev10 reports.
Expand Down Expand Up @@ -3204,7 +3204,7 @@ private BoundStatement BindReturn(ReturnStatementSyntax syntax, DiagnosticBag di
var interactiveInitializerMethod = this.ContainingMemberOrLambda as SynthesizedInteractiveInitializerMethod;
if (interactiveInitializerMethod != null)
{
arg = new BoundDefaultLiteral(interactiveInitializerMethod.GetNonNullSyntaxNode(), interactiveInitializerMethod.ResultType);
arg = new BoundDefaultExpression(interactiveInitializerMethod.GetNonNullSyntaxNode(), interactiveInitializerMethod.ResultType);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/ForEachLoopBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ private bool GetEnumeratorInfo(ref ForEachEnumeratorInfo.Builder builder, BoundE

if ((object)collectionExprType == null) // There's no way to enumerate something without a type.
{
if (collectionExpr.Kind == BoundKind.DefaultLiteral && (object)collectionExpr.Type == null)
if (collectionExpr.Kind == BoundKind.DefaultExpression && (object)collectionExpr.Type == null)
{
diagnostics.Add(ErrorCode.ERR_DefaultNotValid, _syntax.Expression.Location);
diagnostics.Add(ErrorCode.ERR_DefaultLiteralNotValid, _syntax.Expression.Location);
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/PatternSwitchBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ private BoundPatternSwitchLabel BindPatternSwitchSectionLabel(
hasErrors = true;
}

if (caseLabelSyntax.Value.Kind() == SyntaxKind.DefaultLiteralExpression)
{
diagnostics.Add(ErrorCode.WRN_DefaultInSwitch, caseLabelSyntax.Value.Location);
}

// Until we've determined whether or not the switch label is reachable, we assume it
// is. The caller updates isReachable after determining if the label is subsumed.
const bool isReachable = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,8 @@ private Conversion ClassifyImplicitBuiltInConversionFromExpression(BoundExpressi
}
break;

case BoundKind.DefaultLiteral:
var defaultExpression = (BoundDefaultLiteral)sourceExpression;
case BoundKind.DefaultExpression:
var defaultExpression = (BoundDefaultExpression)sourceExpression;
if ((object)defaultExpression.Type == null)
{
return Conversion.DefaultOrNullLiteral;
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/SwitchBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@ private BoundSwitchLabel BindSwitchSectionLabel(SwitchLabelSyntax node, Binder s
hasErrors = true;
}

if (caseLabelSyntax.Value.Kind() == SyntaxKind.DefaultLiteralExpression)
{
diagnostics.Add(ErrorCode.WRN_DefaultInSwitch, caseLabelSyntax.Value.Location);
}

// LabelSymbols for all the switch case labels are created by BuildLabels().
// Fetch the matching switch case label symbols
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public override Symbol ExpressionSymbol
}
}

internal partial class BoundDefaultLiteral
internal partial class BoundDefaultExpression
{
public override ConstantValue ConstantValue
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static bool IsLiteralNull(this BoundExpression node)

public static bool IsLiteralDefault(this BoundExpression node)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps IsDefaultLiteral.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I used this seemingly strange name is because it matches IsLiteralNull (a few lines above).

{
return node.Kind == BoundKind.DefaultLiteral && (object)node.Type == null;
return node.Kind == BoundKind.DefaultExpression && node.Syntax.Kind() == SyntaxKind.DefaultLiteralExpression;
}

// returns true when expression has no side-effects and produces
Expand All @@ -27,7 +27,7 @@ public static bool IsLiteralDefault(this BoundExpression node)
// after some folding/propagation/algebraic transformations.
public static bool IsDefaultValue(this BoundExpression node)
{
if (node.Kind == BoundKind.DefaultLiteral)
if (node.Kind == BoundKind.DefaultExpression)
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@
<Field Name="GetFieldFromHandle" Type="MethodSymbol" Null="allow"/>
</Node>

<Node Name="BoundDefaultLiteral" Base="BoundExpression">
<Node Name="BoundDefaultExpression" Base="BoundExpression">
<!-- Type is null in the case of a default literal, and non-null in the case of a fully-spelled out default operator. -->
<Field Name="Type" Type="TypeSymbol" Override="true" Null="allow"/>
<Field Name="ConstantValueOpt" Type="ConstantValue" Null="allow"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/BoundTree/BoundTreeVisitors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public virtual R Visit(BoundNode node, A arg)
return VisitArrayAccess(node as BoundArrayAccess, arg);
case BoundKind.TypeOfOperator:
return VisitTypeOfOperator(node as BoundTypeOfOperator, arg);
case BoundKind.DefaultLiteral:
return VisitDefaultLiteral(node as BoundDefaultLiteral, arg);
case BoundKind.DefaultExpression:
return VisitDefaultExpression(node as BoundDefaultExpression, arg);
case BoundKind.IsOperator:
return VisitIsOperator(node as BoundIsOperator, arg);
case BoundKind.AsOperator:
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/BoundTree/Constructors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,14 @@ public static BoundBlock SynthesizedNoLocals(SyntaxNode syntax, params BoundStat
}
}

internal partial class BoundDefaultLiteral
internal partial class BoundDefaultExpression
{
public BoundDefaultLiteral(SyntaxNode syntax, TypeSymbol type, bool hasErrors = false)
public BoundDefaultExpression(SyntaxNode syntax, TypeSymbol type, bool hasErrors = false)
: this(syntax, type.GetDefaultValue(), type, hasErrors)
{
}

public BoundDefaultLiteral(SyntaxNode syntax)
public BoundDefaultExpression(SyntaxNode syntax)
: this(syntax, constantValueOpt: null, type: null, hasErrors: false)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/BoundTree/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ public override TResult Accept<TArgument, TResult>(OperationVisitor<TArgument, T
}
}

internal partial class BoundDefaultLiteral : IDefaultValueExpression
internal partial class BoundDefaultExpression : IDefaultValueExpression
{
protected override OperationKind ExpressionKind => OperationKind.DefaultValueExpression;

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/BoundTree/Formatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public override object Display
}
}

internal partial class BoundDefaultLiteral
internal partial class BoundDefaultExpression
{
public override object Display
{
Expand Down
38 changes: 28 additions & 10 deletions src/Compilers/CSharp/Portable/CSharpResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading