Skip to content

Commit eca11f1

Browse files
committed
C#: Adjust getQualifiedName for type parameters
1 parent 3f6beaf commit eca11f1

File tree

9 files changed

+62
-82
lines changed

9 files changed

+62
-82
lines changed

csharp/change-notes/2021-06-16-qualified-names.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
lgtm,codescanning
22
* The following has changed in `Type::getQualifiedName`/`Type::hasQualifiedName`:
3-
- Type parameters now have the qualified name of the declaring generic as
4-
qualifier, and `<i>` as name, where `i` is the index of the type parameter.
5-
Example: in `class C<T> { }`, `T` has qualified name `C.<0>`.
3+
- Type parameters now have the qualified name which is simply the name of the type
4+
parameter itself. Example: in `class C<T> { }`, `T` has qualified name `T`.
65
- Constructed types now use qualified names for type arguments. For example, the
76
qualified name of `C<int>` is `C<System.Int32>`. This also includes array types
87
and pointer types.

csharp/ql/src/semmle/code/csharp/Generics.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ class TypeParameter extends DotNet::TypeParameter, Type, @type_parameter {
186186
UnboundGeneric getGeneric() { type_parameters(this, _, result, _) }
187187

188188
final override predicate hasQualifiedName(string qualifier, string name) {
189-
qualifier = this.getGeneric().getQualifiedName() and
190-
name = "<" + this.getIndex().toString() + ">"
189+
qualifier = "" and
190+
name = this.getName()
191191
}
192192

193193
override string getAPrimaryQlClass() { result = "TypeParameter" }

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void StepQualArg(object @out) { }
111111

112112
void StepElementSetter(object value) => throw null;
113113

114-
static T Apply<S, T>(Func<S, T> f, T t) => throw null;
114+
static T Apply<S, T>(Func<S, T> f, S s) => throw null;
115115

116116
static S[] Map<S, T>(S[] elements, Func<S, T> f) => throw null;
117117

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ edges
2424
| ExternalFlow.cs:54:36:54:47 | object creation of type Object : Object | ExternalFlow.cs:54:13:54:16 | [post] this access [element] : Object |
2525
| ExternalFlow.cs:55:18:55:21 | this access [element] : Object | ExternalFlow.cs:55:18:55:41 | call to method StepElementGetter |
2626
| ExternalFlow.cs:60:35:60:35 | o : Object | ExternalFlow.cs:60:47:60:47 | access to parameter o |
27-
| ExternalFlow.cs:60:64:60:75 | object creation of type Object : Object | ExternalFlow.cs:114:46:114:46 | t : Object |
27+
| ExternalFlow.cs:60:64:60:75 | object creation of type Object : Object | ExternalFlow.cs:114:46:114:46 | s : Object |
2828
| ExternalFlow.cs:65:21:65:60 | call to method Apply : Object | ExternalFlow.cs:66:18:66:18 | access to local variable o |
2929
| ExternalFlow.cs:65:45:65:56 | object creation of type Object : Object | ExternalFlow.cs:65:21:65:60 | call to method Apply : Object |
3030
| ExternalFlow.cs:71:30:71:45 | { ..., ... } [element] : Object | ExternalFlow.cs:72:17:72:20 | access to local variable objs [element] : Object |
@@ -40,7 +40,7 @@ edges
4040
| ExternalFlow.cs:84:25:84:41 | call to method Map [element] : Object | ExternalFlow.cs:85:18:85:22 | access to local variable objs2 [element] : Object |
4141
| ExternalFlow.cs:84:29:84:32 | access to local variable objs [element] : Object | ExternalFlow.cs:84:25:84:41 | call to method Map [element] : Object |
4242
| ExternalFlow.cs:85:18:85:22 | access to local variable objs2 [element] : Object | ExternalFlow.cs:85:18:85:25 | access to array element |
43-
| ExternalFlow.cs:114:46:114:46 | t : Object | ExternalFlow.cs:60:35:60:35 | o : Object |
43+
| ExternalFlow.cs:114:46:114:46 | s : Object | ExternalFlow.cs:60:35:60:35 | o : Object |
4444
| ExternalFlow.cs:116:34:116:41 | elements [element] : Object | ExternalFlow.cs:72:23:72:23 | o : Object |
4545
nodes
4646
| ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
@@ -97,7 +97,7 @@ nodes
9797
| ExternalFlow.cs:84:29:84:32 | access to local variable objs [element] : Object | semmle.label | access to local variable objs [element] : Object |
9898
| ExternalFlow.cs:85:18:85:22 | access to local variable objs2 [element] : Object | semmle.label | access to local variable objs2 [element] : Object |
9999
| ExternalFlow.cs:85:18:85:25 | access to array element | semmle.label | access to array element |
100-
| ExternalFlow.cs:114:46:114:46 | t : Object | semmle.label | t : Object |
100+
| ExternalFlow.cs:114:46:114:46 | s : Object | semmle.label | s : Object |
101101
| ExternalFlow.cs:116:34:116:41 | elements [element] : Object | semmle.label | elements [element] : Object |
102102
invalidModelRow
103103
#select

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class SummaryModelTest extends SummaryModelCsv {
2121
"My.Qltest;D;false;StepPropertySetter;(System.Object);;Argument[0];Property[My.Qltest.D.Property] of Argument[-1];value",
2222
"My.Qltest;D;false;StepElementGetter;();;Element of Argument[-1];ReturnValue;value",
2323
"My.Qltest;D;false;StepElementSetter;(System.Object);;Argument[0];Element of Argument[-1];value",
24-
"My.Qltest;D;false;Apply;(System.Func<My.Qltest.D.Apply.<0>,My.Qltest.D.Apply.<1>>,My.Qltest.D.Apply.<1>);;Argument[1];Parameter[0] of Argument[0];value",
25-
"My.Qltest;D;false;Apply;(System.Func<My.Qltest.D.Apply.<0>,My.Qltest.D.Apply.<1>>,My.Qltest.D.Apply.<1>);;ReturnValue of Argument[0];ReturnValue;value",
26-
"My.Qltest;D;false;Map;(My.Qltest.D.Map.<0>[],System.Func<My.Qltest.D.Map.<0>,My.Qltest.D.Map.<1>>);;Element of Argument[0];Parameter[0] of Argument[1];value",
27-
"My.Qltest;D;false;Map;(My.Qltest.D.Map.<0>[],System.Func<My.Qltest.D.Map.<0>,My.Qltest.D.Map.<1>>);;ReturnValue of Argument[1];Element of ReturnValue;value"
24+
"My.Qltest;D;false;Apply;(System.Func<S,T>,S);;Argument[1];Parameter[0] of Argument[0];value",
25+
"My.Qltest;D;false;Apply;(System.Func<S,T>,S);;ReturnValue of Argument[0];ReturnValue;value",
26+
"My.Qltest;D;false;Map;(S[],System.Func<S,T>);;Element of Argument[0];Parameter[0] of Argument[1];value",
27+
"My.Qltest;D;false;Map;(S[],System.Func<S,T>);;ReturnValue of Argument[1];Element of ReturnValue;value"
2828
]
2929
}
3030
}

csharp/ql/test/library-tests/dataflow/external-models/steps.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class SummaryModelTest extends SummaryModelCsv {
2020
"My.Qltest;C;false;StepPropertySetter;(System.Int32);;Argument[0];Property[My.Qltest.C.Property] of Argument[-1];value",
2121
"My.Qltest;C;false;StepElementGetter;();;Element of Argument[-1];ReturnValue;value",
2222
"My.Qltest;C;false;StepElementSetter;(System.Int32);;Argument[0];Element of Argument[-1];value",
23-
"My.Qltest;C+Generic<>;false;StepGeneric;(My.Qltest.C+Generic<>.<0>);;Argument[0];ReturnValue;value",
24-
"My.Qltest;C+Generic<>;false;StepGeneric2;(My.Qltest.C+Generic<>.StepGeneric2.<0>);;Argument[0];ReturnValue;value"
23+
"My.Qltest;C+Generic<>;false;StepGeneric;(T);;Argument[0];ReturnValue;value",
24+
"My.Qltest;C+Generic<>;false;StepGeneric2;(S);;Argument[0];ReturnValue;value"
2525
]
2626
}
2727
}

0 commit comments

Comments
 (0)