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

Skip to content

Commit 238ed2e

Browse files
committed
C#: Make array and pointer type mentions symmetrical
1 parent a87343d commit 238ed2e

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ private static TypeSyntax GetElementType(TypeSyntax type)
2929
{
3030
case ArrayTypeSyntax ats:
3131
return GetElementType(ats.ElementType);
32-
case NullableTypeSyntax nts:
33-
return GetElementType(nts.ElementType);
3432
case PointerTypeSyntax pts:
3533
return GetElementType(pts.ElementType);
3634
default:
@@ -44,8 +42,7 @@ private static Type GetElementType(Type type)
4442
{
4543
case ArrayType at:
4644
return GetElementType(at.ElementType.Type);
47-
case NamedType nt when nt.symbol.IsBoundNullable() ||
48-
nt.symbol.IsBoundSpan() ||
45+
case NamedType nt when nt.symbol.IsBoundSpan() ||
4946
nt.symbol.IsBoundReadOnlySpan():
5047
return nt.TypeArguments.Single();
5148
case PointerType pt:
@@ -60,6 +57,7 @@ protected override void Populate(TextWriter trapFile)
6057
switch (syntax.Kind())
6158
{
6259
case SyntaxKind.ArrayType:
60+
case SyntaxKind.PointerType:
6361
Emit(trapFile, loc ?? syntax.GetLocation(), parent, type);
6462
Create(cx, GetElementType(syntax), this, GetElementType(type));
6563
return;
@@ -81,12 +79,6 @@ protected override void Populate(TextWriter trapFile)
8179
Emit(trapFile, loc ?? syntax.GetLocation(), parent, type);
8280
tts.Elements.Zip(tt.TupleElements, (s, t) => Create(cx, s.Type, this, t.Type)).Enumerate();
8381
return;
84-
case SyntaxKind.PointerType:
85-
var pts = (PointerTypeSyntax)syntax;
86-
var pt = (PointerType)type;
87-
Emit(trapFile, loc ?? syntax.GetLocation(), parent, type);
88-
Create(cx, pts.ElementType, this, pt.PointedAtType);
89-
return;
9082
case SyntaxKind.GenericName:
9183
var gns = (GenericNameSyntax)syntax;
9284
Emit(trapFile, loc ?? gns.Identifier.GetLocation(), parent, type);

csharp/ql/test/library-tests/types/PrintAst.expected

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,21 @@ types.cs:
5454
# 26| 1: [TypeMention] Byte
5555
# 27| 27: [Method] PointerPointerType
5656
# 27| -1: [TypeMention] Byte**
57-
# 27| 1: [TypeMention] Byte*
58-
# 27| 1: [TypeMention] Byte
57+
# 27| 1: [TypeMention] Byte
5958
# 28| 28: [Method] PointerArrayArrayType
6059
# 28| -1: [TypeMention] Byte*[][]
6160
# 28| 1: [TypeMention] Byte
6261
# 29| 29: [Method] NullableArrayType
6362
# 29| -1: [TypeMention] Nullable
64-
# 29| 1: [TypeMention] Byte
63+
# 29| 1: [TypeMention] Nullable<Byte>
64+
# 29| 1: [TypeMention] Byte
6565
# 30| 30: [Method] NullableArrayArrayType
6666
# 30| -1: [TypeMention] Nullable[]
67-
# 30| 1: [TypeMention] Byte
67+
# 30| 1: [TypeMention] Nullable<Byte>
68+
# 30| 1: [TypeMention] Byte
6869
# 31| 31: [Method] NullableArrayArrayType2
6970
# 31| -1: [TypeMention] Nullable[]
70-
# 31| 1: [TypeMention] Byte
71+
# 31| 1: [TypeMention] Nullable<Byte>
7172
# 32| 32: [Method] Map
7273
# 32| -1: [TypeMention] Map<String,Class>
7374
# 32| 1: [TypeMention] String

0 commit comments

Comments
 (0)