Skip to content

Commit

Permalink
Revert most code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Jan 26, 2019
1 parent 155c367 commit 6c222d9
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 314 deletions.
37 changes: 3 additions & 34 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,8 @@ private BoundExpression CheckValue(BoundExpression expr, BindValueKind valueKind
{
var outer = (BoundSuppressNullableWarningExpression)expr;
var inner = CheckValue(outer.Expression, valueKind, diagnostics);
expr = outer.Update(inner, inner.Type);
return outer.Update(inner, inner.Type);
}
break;
}

bool hasResolutionErrors = false;
Expand Down Expand Up @@ -325,12 +324,8 @@ internal bool CheckValueKind(SyntaxNode node, BoundExpression expr, BindValueKin
return CheckEventValueKind((BoundEventAccess)expr, valueKind, diagnostics);

case BoundKind.SuppressNullableWarningExpression:
if (!IsLegalSuppressionValueKind(valueKind))
{
Error(diagnostics, ErrorCode.ERR_IllegalSuppression, node);
return false;
}

// https://github.com/dotnet/roslyn/issues/29710 We can reach this assertion
Debug.Assert(false);
return CheckValueKind(node, ((BoundSuppressNullableWarningExpression)expr).Expression, valueKind, checkingReceiver, diagnostics);
}

Expand Down Expand Up @@ -525,23 +520,6 @@ internal bool CheckValueKind(SyntaxNode node, BoundExpression expr, BindValueKin
return false;
}

private static bool IsLegalSuppressionValueKind(BindValueKind valueKind)
{
// Need to review allowed uses of the suppression operator
// Tracked by https://github.com/dotnet/roslyn/issues/31297

switch (valueKind)
{
case BindValueKind.RValue:
case BindValueKind.RValueOrMethodGroup:
case BindValueKind.RefOrOut:
return true;
}

// all others are illegal
return false;
}

private static bool CheckNotNamespaceOrType(BoundExpression expr, DiagnosticBag diagnostics)
{
switch (expr.Kind)
Expand Down Expand Up @@ -2422,10 +2400,6 @@ internal static uint GetValEscape(BoundExpression expr, uint scopeOfTheContainin
// only possible in error cases (if possible at all)
return scopeOfTheContainingExpression;

case BoundKind.SuppressNullableWarningExpression:
var suppressed = (BoundSuppressNullableWarningExpression)expr;
return GetValEscape(suppressed.Expression, scopeOfTheContainingExpression);

default:
// in error situations some unexpected nodes could make here
// returning "scopeOfTheContainingExpression" seems safer than throwing.
Expand Down Expand Up @@ -2757,11 +2731,6 @@ internal static bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint
// only possible in error cases (if possible at all)
return false;

case BoundKind.SuppressNullableWarningExpression:
// Need to implement and test escape rules for suppression operator
// Tracked by https://github.com/dotnet/roslyn/issues/31297
goto default;

default:
// in error situations some unexpected nodes could make here
// returning "false" seems safer than throwing.
Expand Down
36 changes: 18 additions & 18 deletions src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ protected BoundExpression CreateConversion(
// nothing else changes
if (source.Kind == BoundKind.TupleLiteral)
{
// We need to handle suppressed tuple literals as well
// Tracked by https://github.com/dotnet/roslyn/issues/32553

var sourceTuple = (BoundTupleLiteral)source;
TupleTypeSymbol.ReportNamesMismatchesIfAny(destination, sourceTuple, diagnostics);
source = new BoundConvertedTupleLiteral(
Expand All @@ -96,23 +93,19 @@ protected BoundExpression CreateConversion(
return CreateMethodGroupConversion(syntax, source, conversion, isCast: isCast, conversionGroupOpt, destination, diagnostics);
}

if (conversion.IsAnonymousFunction && source.KindIgnoringSuppressions() == BoundKind.UnboundLambda)
if (conversion.IsAnonymousFunction && source.Kind == BoundKind.UnboundLambda)
{
return CreateAnonymousFunctionConversion(syntax, source, conversion, isCast: isCast, conversionGroupOpt, destination, diagnostics);
}

if (conversion.IsStackAlloc)
{
Debug.Assert(source.Kind != BoundKind.SuppressNullableWarningExpression);
return CreateStackAllocConversion(syntax, source, conversion, isCast, conversionGroupOpt, destination, diagnostics);
}

if (conversion.IsTupleLiteralConversion ||
(conversion.IsNullable && conversion.UnderlyingConversions[0].IsTupleLiteralConversion))
{
// We need to handle suppressed tuple literals as well
// Tracked by https://github.com/dotnet/roslyn/issues/32553

return CreateTupleLiteralConversion(syntax, (BoundTupleLiteral)source, conversion, isCast: isCast, conversionGroupOpt, destination, diagnostics);
}

Expand All @@ -124,10 +117,9 @@ protected BoundExpression CreateConversion(
}

ConstantValue constantValue = this.FoldConstantConversion(syntax, source, conversion, destination, diagnostics);
if (conversion.Kind == ConversionKind.DefaultOrNullLiteral && source.KindIgnoringSuppressions() == BoundKind.DefaultExpression)
if (conversion.Kind == ConversionKind.DefaultOrNullLiteral && source.Kind == BoundKind.DefaultExpression)
{
var result = ((BoundDefaultExpression)source.RemoveSuppressions()).Update(constantValue, destination);
source = result.WrapWithSuppressionsFrom(source);
source = ((BoundDefaultExpression)source).Update(constantValue, destination);
}

return new BoundConversion(
Expand Down Expand Up @@ -306,15 +298,13 @@ private static BoundExpression CreateAnonymousFunctionConversion(SyntaxNode synt
// UNDONE: Figure out what to do about the error case, where a lambda
// UNDONE: is converted to a delegate that does not match. What to surface then?

Debug.Assert(source.KindIgnoringSuppressions() == BoundKind.UnboundLambda);
var unboundLambda = (UnboundLambda)source.RemoveSuppressions();
var unboundLambda = (UnboundLambda)source;
var boundLambda = unboundLambda.Bind((NamedTypeSymbol)destination);
diagnostics.AddRange(boundLambda.Diagnostics);

Debug.Assert(unboundLambda.WasCompilerGenerated == source.WasCompilerGenerated);
return new BoundConversion(
syntax,
boundLambda.WrapWithSuppressionsFrom(source),
boundLambda,
conversion,
@checked: false,
explicitCastInCode: isCast,
Expand All @@ -326,7 +316,7 @@ private static BoundExpression CreateAnonymousFunctionConversion(SyntaxNode synt

private BoundExpression CreateMethodGroupConversion(SyntaxNode syntax, BoundExpression source, Conversion conversion, bool isCast, ConversionGroup conversionGroup, TypeSymbol destination, DiagnosticBag diagnostics)
{
BoundMethodGroup group = FixMethodGroupWithTypeOrValue((BoundMethodGroup)source.RemoveSuppressions(), conversion, diagnostics);
BoundMethodGroup group = FixMethodGroupWithTypeOrValue((BoundMethodGroup)source, conversion, diagnostics);
BoundExpression receiverOpt = group.ReceiverOpt;
MethodSymbol method = conversion.Method;
bool hasErrors = false;
Expand All @@ -342,7 +332,7 @@ private BoundExpression CreateMethodGroupConversion(SyntaxNode syntax, BoundExpr
hasErrors = true;
}

return new BoundConversion(syntax, group.WrapWithSuppressionsFrom(source), conversion, @checked: false, explicitCastInCode: isCast, conversionGroup, constantValueOpt: ConstantValue.NotAvailable, type: destination, hasErrors: hasErrors) { WasCompilerGenerated = source.WasCompilerGenerated };
return new BoundConversion(syntax, group, conversion, @checked: false, explicitCastInCode: isCast, conversionGroup, constantValueOpt: ConstantValue.NotAvailable, type: destination, hasErrors: hasErrors) { WasCompilerGenerated = source.WasCompilerGenerated };
}

private BoundExpression CreateStackAllocConversion(SyntaxNode syntax, BoundExpression source, Conversion conversion, bool isCast, ConversionGroup conversionGroup, TypeSymbol destination, DiagnosticBag diagnostics)
Expand Down Expand Up @@ -478,9 +468,19 @@ private BoundExpression CreateTupleLiteralConversion(SyntaxNode syntax, BoundTup
return result;
}

private static bool IsMethodGroupWithTypeOrValueReceiver(BoundNode node)
{
if (node.Kind != BoundKind.MethodGroup)
{
return false;
}

return Binder.IsTypeOrValueExpression(((BoundMethodGroup)node).ReceiverOpt);
}

private BoundMethodGroup FixMethodGroupWithTypeOrValue(BoundMethodGroup group, Conversion conversion, DiagnosticBag diagnostics)
{
if (!IsTypeOrValueExpression(group.ReceiverOpt))
if (!IsMethodGroupWithTypeOrValueReceiver(group))
{
return group;
}
Expand Down
Loading

0 comments on commit 6c222d9

Please sign in to comment.