Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5552c2e

Browse files
authored
Merge pull request #2563 from calumgrant/cs/tuple-expr
C#: Handle tuple expressions
2 parents 367d13c + 0f178be commit 5552c2e

6 files changed

Lines changed: 25 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515

1616
# It's useful (though not required) to be able to unpack codeql in the ql checkout itself
1717
/codeql/
18+
.vscode/settings.json
19+
csharp/extractor/Semmle.Extraction.CSharp.Driver/Properties/launchSettings.json

change-notes/1.24/analysis-csharp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ The following changes in version 1.24 affect C# analysis in all applications.
1919

2020
## Changes to code extraction
2121

22+
* Tuple expressions, for example `(int,bool)` in `default((int,bool))` are now extracted correctly.
23+
2224
## Changes to libraries
2325

2426
* The taint tracking library now tracks flow through (implicit or explicit) conversion operator calls.

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Factory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ internal static Expression Create(ExpressionNodeInfo info)
129129
case SyntaxKind.ArrayType:
130130
case SyntaxKind.PredefinedType:
131131
case SyntaxKind.NullableType:
132+
case SyntaxKind.TupleType:
132133
return TypeAccess.Create(info);
133134

134135
case SyntaxKind.TypeOfExpression:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| expressions.cs:492:29:492:41 | access to type (Int32,String) | expressions.cs:492:29:492:41 | (Int32,String) |
2+
| expressions.cs:493:29:493:49 | access to type (Boolean,Int32[],Object) | expressions.cs:493:29:493:49 | (Boolean,Int32[],Object) |
3+
| expressions.cs:494:28:494:40 | access to type (Int32,String) | expressions.cs:492:29:492:41 | (Int32,String) |
4+
| expressions.cs:495:28:495:49 | access to type (Boolean,Int32[],dynamic) | expressions.cs:495:28:495:49 | (Boolean,Int32[],dynamic) |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from TypeAccess access, TupleType type
4+
where type = access.getTarget()
5+
select access, type

csharp/ql/test/library-tests/expressions/expressions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,15 @@ class ExpressionDepth
484484
const int d = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
485485
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
486486
}
487+
488+
class TupleExprs
489+
{
490+
void Test()
491+
{
492+
var a = default((int, string));
493+
var b = default((bool, int[], object));
494+
var x = typeof((int, string));
495+
var y = typeof((bool, int[], dynamic));
496+
}
497+
}
487498
}

0 commit comments

Comments
 (0)