-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose if a Binary/Unary operator was 'Lifted' at the IExpression lev…
…el. (#14779) * Expose if a Binary/Unary operator was 'Lifted' at the IExpression level. * Update public API. * Share computed value. * Remove unnecessary extension. * Update test code. * Remove extension method. * Fixup tests. * Fixup tests. * Fixup tests. * Fix instances of Invalid operations with nullable * Compound assignments also need to state if they're lifted. * Move tests. * Move tests. * Move tests. * Simplify comment. * Case things consistently. * Use F instead of Foo. Because Foo is bad.
- Loading branch information
1 parent
fdb83fa
commit e63e0d4
Showing
20 changed files
with
1,037 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IBinaryOperatorExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.UnitTests | ||
{ | ||
public partial class IOperationTests : SemanticModelTestBase | ||
{ | ||
[Fact] | ||
public void VerifyLiftedBinaryOperators1() | ||
{ | ||
var source = @" | ||
class C | ||
{ | ||
void F(int? x, int? y) | ||
{ | ||
var z = /*<bind>*/x + y/*</bind>*/; | ||
} | ||
}"; | ||
|
||
string expectedOperationTree = | ||
@"IBinaryOperatorExpression (BinaryOperationKind.IntegerAdd-IsLifted) (OperationKind.BinaryOperatorExpression, Type: System.Int32?) (Syntax: 'x + y') | ||
Left: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32?) (Syntax: 'x') | ||
Right: IParameterReferenceExpression: y (OperationKind.ParameterReferenceExpression, Type: System.Int32?) (Syntax: 'y')"; | ||
|
||
VerifyOperationTreeForTest<BinaryExpressionSyntax>(source, expectedOperationTree); | ||
} | ||
|
||
[Fact] | ||
public void VerifyNonLiftedBinaryOperators1() | ||
{ | ||
var source = @" | ||
class C | ||
{ | ||
void F(int x, int y) | ||
{ | ||
var z = /*<bind>*/x + y/*</bind>*/; | ||
} | ||
}"; | ||
|
||
string expectedOperationTree = | ||
@"IBinaryOperatorExpression (BinaryOperationKind.IntegerAdd) (OperationKind.BinaryOperatorExpression, Type: System.Int32) (Syntax: 'x + y') | ||
Left: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'x') | ||
Right: IParameterReferenceExpression: y (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'y')"; | ||
|
||
VerifyOperationTreeForTest<BinaryExpressionSyntax>(source, expectedOperationTree); | ||
} | ||
|
||
[Fact] | ||
public void VerifyLiftedUserDefinedBinaryOperators1() | ||
{ | ||
var source = @" | ||
struct C | ||
{ | ||
public static C operator +(C c1, C c2) { } | ||
void F(C? x, C? y) | ||
{ | ||
var z = /*<bind>*/x + y/*</bind>*/; | ||
} | ||
}"; | ||
|
||
string expectedOperationTree = | ||
@"IBinaryOperatorExpression (BinaryOperationKind.OperatorMethodAdd-IsLifted) (OperatorMethod: C C.op_Addition(C c1, C c2)) (OperationKind.BinaryOperatorExpression, Type: C?) (Syntax: 'x + y') | ||
Left: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: C?) (Syntax: 'x') | ||
Right: IParameterReferenceExpression: y (OperationKind.ParameterReferenceExpression, Type: C?) (Syntax: 'y')"; | ||
|
||
VerifyOperationTreeForTest<BinaryExpressionSyntax>(source, expectedOperationTree); | ||
} | ||
|
||
[Fact] | ||
public void VerifyNonLiftedUserDefinedBinaryOperators1() | ||
{ | ||
var source = @" | ||
struct C | ||
{ | ||
public static C operator +(C c1, C c2) { } | ||
void F(C x, C y) | ||
{ | ||
var z = /*<bind>*/x + y/*</bind>*/; | ||
} | ||
}"; | ||
|
||
string expectedOperationTree = | ||
@"IBinaryOperatorExpression (BinaryOperationKind.OperatorMethodAdd) (OperatorMethod: C C.op_Addition(C c1, C c2)) (OperationKind.BinaryOperatorExpression, Type: C) (Syntax: 'x + y') | ||
Left: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'x') | ||
Right: IParameterReferenceExpression: y (OperationKind.ParameterReferenceExpression, Type: C) (Syntax: 'y')"; | ||
|
||
VerifyOperationTreeForTest<BinaryExpressionSyntax>(source, expectedOperationTree); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.