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

Skip to content

Commit 85c9459

Browse files
committed
C#: Add more tests showing incorrect extraction.
1 parent 10181e9 commit 85c9459

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

csharp/ql/test/library-tests/csharp8/NullableRefTypes.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,22 @@ void ExceptionFlow()
205205

206206
Check(y); // y not null - finally flow is detected
207207
}
208+
209+
string InvocationTest(object? o)
210+
{
211+
var t = o?.GetType(); // Not null (incorrect - should be null maybe)
212+
return t.ToString(); // Not null
213+
}
214+
215+
void ElementTest(List<string>? list)
216+
{
217+
string? a = GetSelf()?.Field; // Not null (incorrect - should be null maybe)
218+
string? b = list?[0]; // Not null (incorrect - should be null maybe)
219+
string c = list[0]; // Not null
220+
string d = GetSelf().Field; // Not null
221+
}
222+
223+
protected abstract TestNullableFlowStates? GetSelf();
224+
225+
string Field;
208226
}

csharp/ql/test/library-tests/csharp8/NullableRefTypes.expected

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ returnTypes
201201
| NullableRefTypes.cs:177:25:177:29 | Count | int! |
202202
| NullableRefTypes.cs:179:10:179:22 | LoopUnrolling | Void! |
203203
| NullableRefTypes.cs:193:10:193:22 | ExceptionFlow | Void! |
204+
| NullableRefTypes.cs:209:12:209:25 | InvocationTest | string! |
205+
| NullableRefTypes.cs:215:10:215:20 | ElementTest | Void! |
206+
| NullableRefTypes.cs:223:48:223:54 | GetSelf | TestNullableFlowStates? |
204207
methodTypeArguments
205208
| NullableRefTypes.cs:51:12:51:15 | Q | 0 | MyClass! |
206209
| NullableRefTypes.cs:51:12:51:15 | Q | 0 | MyClass? |
@@ -357,6 +360,32 @@ expressionTypes
357360
| NullableRefTypes.cs:206:9:206:16 | call to method Check | Void! |
358361
| NullableRefTypes.cs:206:9:206:16 | this access | TestNullableFlowStates |
359362
| NullableRefTypes.cs:206:15:206:15 | access to local variable y | string! |
363+
| NullableRefTypes.cs:211:13:211:13 | access to local variable t | Type? |
364+
| NullableRefTypes.cs:211:13:211:28 | Type t = ... | Type? |
365+
| NullableRefTypes.cs:211:17:211:17 | access to parameter o | object? |
366+
| NullableRefTypes.cs:211:19:211:28 | call to method GetType | Type! |
367+
| NullableRefTypes.cs:212:16:212:16 | access to local variable t | Type? |
368+
| NullableRefTypes.cs:212:16:212:27 | call to method ToString | string! |
369+
| NullableRefTypes.cs:217:17:217:17 | access to local variable a | string! |
370+
| NullableRefTypes.cs:217:17:217:36 | String a = ... | string! |
371+
| NullableRefTypes.cs:217:21:217:29 | call to method GetSelf | TestNullableFlowStates? |
372+
| NullableRefTypes.cs:217:21:217:29 | this access | TestNullableFlowStates |
373+
| NullableRefTypes.cs:217:31:217:36 | access to field Field | string! |
374+
| NullableRefTypes.cs:218:17:218:17 | access to local variable b | string! |
375+
| NullableRefTypes.cs:218:17:218:28 | String b = ... | string! |
376+
| NullableRefTypes.cs:218:21:218:24 | access to parameter list | List<string!>? |
377+
| NullableRefTypes.cs:218:26:218:28 | access to indexer | string |
378+
| NullableRefTypes.cs:218:27:218:27 | 0 | int! |
379+
| NullableRefTypes.cs:219:16:219:16 | access to local variable c | string! |
380+
| NullableRefTypes.cs:219:16:219:26 | String c = ... | string! |
381+
| NullableRefTypes.cs:219:20:219:23 | access to parameter list | List<string!>? |
382+
| NullableRefTypes.cs:219:20:219:26 | access to indexer | string! |
383+
| NullableRefTypes.cs:219:25:219:25 | 0 | int! |
384+
| NullableRefTypes.cs:220:16:220:16 | access to local variable d | string! |
385+
| NullableRefTypes.cs:220:16:220:34 | String d = ... | string! |
386+
| NullableRefTypes.cs:220:20:220:28 | call to method GetSelf | TestNullableFlowStates? |
387+
| NullableRefTypes.cs:220:20:220:28 | this access | TestNullableFlowStates |
388+
| NullableRefTypes.cs:220:20:220:34 | access to field Field | string! |
360389
exprFlowState
361390
| NullableRefTypes.cs:13:19:13:22 | null | Maybe null |
362391
| NullableRefTypes.cs:14:18:14:21 | this access | Not null |
@@ -436,3 +465,17 @@ exprFlowState
436465
| NullableRefTypes.cs:203:17:203:26 | "not null" | Not null |
437466
| NullableRefTypes.cs:206:9:206:16 | call to method Check | Not null |
438467
| NullableRefTypes.cs:206:15:206:15 | access to local variable y | Not null |
468+
| NullableRefTypes.cs:211:17:211:17 | access to parameter o | Maybe null |
469+
| NullableRefTypes.cs:211:19:211:28 | call to method GetType | Not null |
470+
| NullableRefTypes.cs:212:16:212:16 | access to local variable t | Maybe null |
471+
| NullableRefTypes.cs:212:16:212:27 | call to method ToString | Not null |
472+
| NullableRefTypes.cs:217:21:217:29 | call to method GetSelf | Maybe null |
473+
| NullableRefTypes.cs:217:31:217:36 | access to field Field | Not null |
474+
| NullableRefTypes.cs:218:21:218:24 | access to parameter list | Maybe null |
475+
| NullableRefTypes.cs:218:26:218:28 | access to indexer | Not null |
476+
| NullableRefTypes.cs:218:27:218:27 | 0 | Not null |
477+
| NullableRefTypes.cs:219:20:219:23 | access to parameter list | Maybe null |
478+
| NullableRefTypes.cs:219:20:219:26 | access to indexer | Not null |
479+
| NullableRefTypes.cs:219:25:219:25 | 0 | Not null |
480+
| NullableRefTypes.cs:220:20:220:28 | call to method GetSelf | Maybe null |
481+
| NullableRefTypes.cs:220:20:220:34 | access to field Field | Not null |

0 commit comments

Comments
 (0)