Skip to content

Commit 33daa2c

Browse files
committed
Fix container type extraction of tuple members
1 parent 4f4bf59 commit 33daa2c

File tree

5 files changed

+192
-182
lines changed

5 files changed

+192
-182
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedSymbol.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ protected CachedSymbol(Context cx, T init)
1616
{
1717
}
1818

19-
public virtual Type? ContainingType => Symbol.ContainingType is not null ? Type.Create(Context, Symbol.ContainingType) : null;
19+
public virtual Type? ContainingType => Symbol.ContainingType is not null
20+
? Symbol.ContainingType.IsTupleType
21+
? NamedType.CreateNamedTypeFromTupleType(Context, Symbol.ContainingType)
22+
: Type.Create(Context, Symbol.ContainingType)
23+
: null;
2024

2125
public void PopulateModifiers(TextWriter trapFile)
2226
{

csharp/ql/src/semmle/code/csharp/dataflow/LibraryTypeDataFlow.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,8 +1848,15 @@ class SystemTupleFlow extends LibraryTypeDataFlow, ValueOrRefType {
18481848
c.(Constructor).getDeclaringType() = this and
18491849
t = this
18501850
or
1851-
c = this.getAMethod(any(string name | name.regexpMatch("Create(<,*>)?"))) and
1852-
t = c.getReturnType().getUnboundDeclaration()
1851+
exists(ValueOrRefType namedType |
1852+
namedType = this or namedType = this.(TupleType).getUnderlyingType()
1853+
|
1854+
c = namedType.getAMethod(any(string name | name.regexpMatch("Create(<,*>)?"))) and
1855+
(
1856+
t = c.getReturnType().getUnboundDeclaration() or
1857+
t = c.getReturnType().(TupleType).getUnderlyingType().getUnboundDeclaration()
1858+
)
1859+
)
18531860
)
18541861
or
18551862
c =

csharp/ql/test/library-tests/csharp7/TupleTypes.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
| (Int32,Double) | (int, double) | ValueTuple<Int32, Double> | 2 | 0 | CSharp7.cs:215:6:215:8 | Item1 |
44
| (Int32,Double) | (int, double) | ValueTuple<Int32, Double> | 2 | 1 | CSharp7.cs:215:11:215:16 | Item2 |
55
| (Int32,Int32) | (int, int) | ValueTuple<Int32, Int32> | 2 | 0 | CSharp7.cs:64:10:64:10 | Item1 |
6-
| (Int32,Int32) | (int, int) | ValueTuple<Int32, Int32> | 2 | 1 | file://:0:0:0:0 | Item2 |
6+
| (Int32,Int32) | (int, int) | ValueTuple<Int32, Int32> | 2 | 1 | CSharp7.cs:64:17:64:17 | Item2 |
77
| (String,Int32) | (string, int) | ValueTuple<String, Int32> | 2 | 0 | CSharp7.cs:84:17:84:17 | Item1 |
8-
| (String,Int32) | (string, int) | ValueTuple<String, Int32> | 2 | 1 | file://:0:0:0:0 | Item2 |
8+
| (String,Int32) | (string, int) | ValueTuple<String, Int32> | 2 | 1 | CSharp7.cs:84:23:84:23 | Item2 |
99
| (String,String) | (string, string) | ValueTuple<String, String> | 2 | 0 | CSharp7.cs:89:19:89:27 | Item1 |
1010
| (String,String) | (string, string) | ValueTuple<String, String> | 2 | 1 | CSharp7.cs:89:30:89:33 | Item2 |

0 commit comments

Comments
 (0)