C#: Add some suppress nullable warning testcases and update expected output.

This commit is contained in:
Michael Nebel
2024-04-12 09:31:31 +02:00
parent 854dfb35c1
commit 1e59def89d
7 changed files with 52 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
| file://:0:0:0:0 | Rectangle | expressions.cs:351:18:351:26 | call to constructor Object | file://:0:0:0:0 | Object |
| file://:0:0:0:0 | Rectangle2 | expressions.cs:361:18:361:27 | call to constructor Object | file://:0:0:0:0 | Object |
| file://:0:0:0:0 | ReducedClass | ReducedExpression.cs:2:7:2:18 | call to constructor Object | file://:0:0:0:0 | Object |
| file://:0:0:0:0 | SuppressNullableWarning | expressions.cs:522:11:522:33 | call to constructor Object | file://:0:0:0:0 | Object |
| file://:0:0:0:0 | TestConversionOperator | expressions.cs:330:11:330:32 | call to constructor Object | file://:0:0:0:0 | Object |
| file://:0:0:0:0 | TestCreations | expressions.cs:383:18:383:30 | call to constructor Object | file://:0:0:0:0 | Object |
| file://:0:0:0:0 | TestUnaryOperator | expressions.cs:292:11:292:27 | call to constructor Object | file://:0:0:0:0 | Object |

View File

@@ -1,3 +1,5 @@
expressions.cs:
# 530| [MethodCall] call to method Api
FoldedLiterals.cs:
# 1| [Class] FoldedLiterals
# 3| 5: [Method] Test
@@ -2406,3 +2408,24 @@ expressions.cs:
# 520| -1: [TypeMention] object
# 520| 3: [ConstructorInitializer] call to constructor ClassC1
# 520| 0: [ParameterAccess] access to parameter oc2
# 522| 24: [Class] SuppressNullableWarning
# 525| 5: [Method] Api
# 525| -1: [TypeMention] object
# 525| 4: [ObjectCreation] object creation of type Object
# 525| 0: [TypeMention] object
# 527| 6: [Method] Test
# 527| -1: [TypeMention] Void
#-----| 2: (Parameters)
# 527| 0: [Parameter] arg0
# 527| -1: [TypeMention] object
# 528| 4: [BlockStmt] {...}
# 529| 0: [LocalVariableDeclStmt] ... ...;
# 529| 0: [LocalVariableDeclAndInitExpr] Object x = ...
# 529| -1: [TypeMention] object
# 529| 0: [LocalVariableAccess] access to local variable x
# 529| 1: [SuppressNullableWarningExpr] ...!
# 529| 0: [ParameterAccess] access to parameter arg0
# 530| 1: [LocalVariableDeclStmt] ... ...;
# 530| 0: [LocalVariableDeclAndInitExpr] Object y = ...
# 530| -1: [TypeMention] object
# 530| 0: [LocalVariableAccess] access to local variable y

View File

@@ -70,3 +70,4 @@
| expressions.cs:483:17:483:26 | access to field value | expressions.cs:483:17:483:20 | this access |
| expressions.cs:488:32:488:39 | access to field value | expressions.cs:488:32:488:33 | access to parameter c1 |
| expressions.cs:488:43:488:50 | access to field value | expressions.cs:488:43:488:44 | access to parameter c2 |
| expressions.cs:530:21:530:25 | call to method Api | expressions.cs:530:21:530:25 | this access |

View File

@@ -0,0 +1 @@
| expressions.cs:529:21:529:25 | ...! |

View File

@@ -0,0 +1,3 @@
import csharp
select any(SuppressNullableWarningExpr e)

View File

@@ -518,4 +518,16 @@ namespace Expressions
class ClassC1(object oc1) { }
class ClassC2(object oc2) : ClassC1(oc2) { }
class SuppressNullableWarning
{
public object? Api() => new object();
public void Test(object? arg0)
{
var x = arg0!;
var y = Api()!;
}
}
}

View File

@@ -95,6 +95,17 @@ namespace Test
var result = new DataSet();
adapter.Fill(result);
}
// BAD: Input from the command line. (also implicitly check flow via suppress nullable warning `!`)
using (var connection = new SqlConnection(connectionString))
{
var queryString = "SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='"
+ Console.ReadLine()! + "' ORDER BY PRICE";
var cmd = new SqlCommand(queryString);
var adapter = new SqlDataAdapter(cmd);
var result = new DataSet();
adapter.Fill(result);
}
}
System.Windows.Forms.TextBox box1;