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

More tests and suggestions on default literal #18604

Merged
merged 14 commits into from
Apr 14, 2017
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ private BoundExpression BindUnaryOperatorCore(CSharpSyntaxNode node, string oper
{
UnaryOperatorKind kind = SyntaxKindToUnaryOperatorKind(node.Kind());

bool isOperandTypeNull = (object)operand.Type == null;
bool isOperandTypeNull = operand.IsLiteralNull();
if (isOperandTypeNull)
Copy link
Member

Choose a reason for hiding this comment

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

Are we reporting an error for an operand with no type, for instance BoundMethodGroup?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, added test for method group and null.

{
// Dev10 does not allow unary prefix operators to be applied to the null literal
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/ForEachLoopBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ 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.DefaultExpression && (object)collectionExpr.Type == null)
if (collectionExpr.Kind == BoundKind.DefaultExpression)
{
diagnostics.Add(ErrorCode.ERR_DefaultLiteralNotValid, _syntax.Expression.Location);
}
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 @@ -518,7 +518,7 @@
</Node>

<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. -->
<!-- Type is null in the case of a default literal, and non-null for default(T). -->
<Field Name="Type" Type="TypeSymbol" Override="true" Null="allow"/>
<Field Name="ConstantValueOpt" Type="ConstantValue" Null="allow"/>
</Node>
Expand Down
5 changes: 0 additions & 5 deletions src/Compilers/CSharp/Portable/BoundTree/Constructors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,6 @@ public BoundDefaultExpression(SyntaxNode syntax, TypeSymbol type, bool hasErrors
: this(syntax, type.GetDefaultValue(), type, hasErrors)
{
}

public BoundDefaultExpression(SyntaxNode syntax)
: this(syntax, constantValueOpt: null, type: null, hasErrors: false)
{
}
}

internal partial class BoundTryStatement
Expand Down
4 changes: 2 additions & 2 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.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,7 @@ If such a class is used as a base class and if the deriving class defines a dest
<value>No best type found for implicitly-typed array</value>
</data>
<data name="ERR_AnonymousTypePropertyAssignedBadValue" xml:space="preserve">
<value>Cannot assign {0} to anonymous type property</value>
<value>Cannot assign '{0}' to anonymous type property</value>
</data>
<data name="ERR_ExpressionTreeContainsBaseAccess" xml:space="preserve">
<value>An expression tree may not contain a base access</value>
Expand Down Expand Up @@ -4886,7 +4886,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<value>Deconstruct assignment requires an expression with a type on the right-hand-side.</value>
</data>
<data name="ERR_SwitchExpressionValueExpected" xml:space="preserve">
<value>The switch expression must be a value; found {0}.</value>
<value>The switch expression must be a value; found '{0}'.</value>
</data>
<data name="ERR_PatternIsSubsumed" xml:space="preserve">
<value>The switch case has already been handled by a previous case.</value>
Expand Down
Loading