Skip to content

Commit

Permalink
Fix issue with EE scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Nov 5, 2016
1 parent ecce74d commit 31e9421
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal sealed class CompilationContext
MethodDebugInfo<TypeSymbol, LocalSymbol> methodDebugInfo,
CSharpSyntaxNode syntax)
{
Debug.Assert((syntax == null) || (syntax is ExpressionSyntax) || (syntax is LocalDeclarationStatementSyntax));
Debug.Assert((syntax == null) || (syntax is ExpressionSyntax) || (syntax is LocalDeclarationStatementSyntax) || (syntax is ExpressionStatementSyntax));

// TODO: syntax.SyntaxTree should probably be added to the compilation,
// but it isn't rooted by a CompilationUnitSyntax so it doesn't work (yet).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.ExpressionEvaluator;
using Microsoft.DiaSymReader;
Expand Down Expand Up @@ -301,11 +302,17 @@ private static MethodSymbol GetSynthesizedMethod(CommonPEModuleBuilder moduleBui
Debug.Assert((statementSyntax == null) || !statementDiagnostics.HasAnyErrors());
statementDiagnostics.Free();

if (statementSyntax != null && !statementSyntax.IsKind(SyntaxKind.ExpressionStatement)) // Prefer to parse expression statements as expressions.
// Prefer to parse expression statements (except deconstruction-declarations) as expressions.
var isExpressionStatement = statementSyntax.IsKind(SyntaxKind.ExpressionStatement);
var isDeconstructionDeclaration = isExpressionStatement &&
IsDeconstructionDeclaration((ExpressionStatementSyntax)statementSyntax);

if (statementSyntax != null && (!isExpressionStatement || isDeconstructionDeclaration))
{
formatSpecifiers = null;

if (statementSyntax.IsKind(SyntaxKind.LocalDeclarationStatement))
if (statementSyntax.IsKind(SyntaxKind.LocalDeclarationStatement) ||
isDeconstructionDeclaration)
{
return statementSyntax;
}
Expand All @@ -318,6 +325,15 @@ private static MethodSymbol GetSynthesizedMethod(CommonPEModuleBuilder moduleBui
return expr.ParseExpression(diagnostics, allowFormatSpecifiers: true, formatSpecifiers: out formatSpecifiers);
}

private static bool IsDeconstructionDeclaration(ExpressionStatementSyntax expressionStatement)
{
if (!expressionStatement.Expression.IsKind(SyntaxKind.SimpleAssignmentExpression))
{
return false;
}
return ((AssignmentExpressionSyntax)expressionStatement.Expression).IsDeconstructionDeclaration();
}

internal override CompileResult CompileAssignment(
string target,
string expr,
Expand Down

0 comments on commit 31e9421

Please sign in to comment.