Skip to content

Commit ae36359

Browse files
committed
C#: Fix typementions of arrays.
1 parent 36b42de commit ae36359

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ class TypeMention : FreshEntity
2222
Loc = loc;
2323
}
2424

25+
static TypeSyntax GetArrayElementType(ArrayTypeSyntax array)
26+
{
27+
return array.ElementType is ArrayTypeSyntax a ?
28+
GetArrayElementType(a) :
29+
array.ElementType;
30+
}
31+
32+
static Type GetArrayElementType(Type t)
33+
{
34+
return t is ArrayType a ? GetArrayElementType(a.ElementType.Type) : t;
35+
}
36+
2537
void Populate()
2638
{
2739
switch (Syntax.Kind())
@@ -30,7 +42,7 @@ void Populate()
3042
var ats = (ArrayTypeSyntax)Syntax;
3143
var at = (ArrayType)Type;
3244
Emit(Loc ?? Syntax.GetLocation(), Parent, Type);
33-
Create(cx, ats.ElementType, this, at.ElementType);
45+
Create(cx, GetArrayElementType(ats), this, GetArrayElementType(at));
3446
return;
3547
case SyntaxKind.NullableType:
3648
var nts = (NullableTypeSyntax)Syntax;

csharp/ql/test/library-tests/regressions/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,9 @@ class EmbeddedTypesManager<
159159
}
160160
}
161161

162+
unsafe class ArrayTypesTest
163+
{
164+
int*[][] field;
165+
}
166+
162167
// semmle-extractor-options: /r:System.Dynamic.Runtime.dll

csharp/ql/test/library-tests/regressions/TypeMentions.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@
7676
| Program.cs:157:31:157:50 | EmbeddedTypesManager<,> |
7777
| Program.cs:157:52:157:72 | TEmbeddedTypesManager |
7878
| Program.cs:157:75:157:87 | TEmbeddedType |
79+
| Program.cs:164:3:164:5 | Int32 |
80+
| Program.cs:164:3:164:6 | Int32* |
81+
| Program.cs:164:3:164:10 | Int32*[][] |

0 commit comments

Comments
 (0)