Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Jul 3, 2024
1 parent b211358 commit a79e9b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private static ProgramState[] ProcessBoolCollectionMethods(ProgramState state, I
CollectionConstraint constraint when constraint == CollectionConstraint.Empty => state.SetOperationConstraint(invocation, BoolConstraint.False).ToArray(),
CollectionConstraint constraint when constraint == CollectionConstraint.NotEmpty && HasNoParameters(invocation.TargetMethod) =>
state.SetOperationConstraint(invocation, BoolConstraint.True).ToArray(),
CollectionConstraint constraint when constraint == CollectionConstraint.NotEmpty => state.ToArray(),
_ when HasNoParameters(invocation.TargetMethod) =>
[
state.SetOperationConstraint(invocation, BoolConstraint.True).SetSymbolConstraint(instanceSymbol, CollectionConstraint.NotEmpty),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void InstanceReference_SetsNotNull_VB()
{
const string code = """
Dim FromMe As Sample = Me
Tag(""Me"", FromMe)
Tag("Me", FromMe)
""";
var validator = SETestContext.CreateVB(code).Validator;
validator.ValidateContainsOperation(OperationKind.InstanceReference);
Expand Down Expand Up @@ -527,7 +527,7 @@ void Main()
staticField = null;
Tag("BeforeField", field);
Tag("BeforeStaticField", staticField);
{invocation}
{{invocation}}
Tag("AfterField", field);
Tag("AfterStaticField", staticField);
}
Expand Down Expand Up @@ -660,15 +660,15 @@ public void Instance_InstanceMethodCall_ClearsFieldInConsistentManner()
{
Tag("IfBefore", ObjectField);
InstanceMethod();
Tag(""IfAfter"", ObjectField);
Tag("IfAfter", ObjectField);
}
else
{
Tag("ElseBefore"", ObjectField);
Tag("ElseBefore", ObjectField);
InstanceMethod();
Tag("ElseAfter", ObjectField);
}
Tag(""AfterIfElse"", ObjectField);
Tag("AfterIfElse", ObjectField);
""";
var invalidateConstraint = DummyConstraint.Dummy;
var dontInvalidateConstraint = LockConstraint.Held;
Expand Down Expand Up @@ -822,7 +822,7 @@ public void Invocation_StaticMethodCall_DoesNotClearInstanceFields(string invoca
{invocation}
Tag("AfterField", ObjectField);
Tag("AfterStaticField", StaticObjectField);
""";
""";
var validator = SETestContext.CreateCS(code).Validator;
validator.ValidateContainsOperation(OperationKind.Invocation);
validator.TagValue("BeforeField").Should().HaveOnlyConstraint(ObjectConstraint.Null);
Expand Down Expand Up @@ -954,7 +954,7 @@ public void Invocation_LinqEnumerableAndQueryable_NotNull(string expression)
{
var code = $"""
var value = {expression};
Tag(""Value"", value);
Tag("Value", value);
""";
var enumerableValidator = SETestContext.CreateCS(code, "IEnumerable<object> arg").Validator;
enumerableValidator.TagValue("Value").Should().HaveOnlyConstraint(ObjectConstraint.NotNull);
Expand Down Expand Up @@ -994,7 +994,7 @@ public void Invocation_LinqEnumerable_Unknown_Int(string expression)
{
var code = $"""
var value = arg.{expression};
Tag(""Value"", value);
Tag("Value", value);
""";
var validator = SETestContext.CreateCS(code, $"IEnumerable<int> arg").Validator;
validator.TagValue("Value").Should().HaveOnlyConstraint(ObjectConstraint.NotNull);
Expand All @@ -1007,7 +1007,7 @@ public void Invocation_LinqEnumerable_Unknown_Object(string expression)
{
var code = $"""
var value = arg.{expression};
Tag(""Value"", value);
Tag("Value", value);
""";
var validator = SETestContext.CreateCS(code, $"IEnumerable<object> arg").Validator;
validator.TagValue("Value").Should().BeNull();
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public void Invocation_BoolCollectionMethod_NoParameters_CollectionEmpty()
var value = collection.Any();
Tag("Value", value);
""";
var enumerableValidator = SETestContext.CreateCS(code, $"List<object> collection").Validator;
var enumerableValidator = SETestContext.CreateCS(code, $"List<int> collection").Validator;
var collectionSymbol = enumerableValidator.Symbol("collection");
var valueSymbol = enumerableValidator.Symbol("value");
enumerableValidator.TagStates("Value").Should().HaveCount(1)
Expand All @@ -1047,11 +1047,11 @@ public void Invocation_BoolCollectionMethod_NoParameters_CollectionEmpty()
public void Invocation_BoolCollectionMethod_NoParameters_CollectionNotEmpty()
{
var code = """
collection.Add(new object());
collection.Add(1);
var value = collection.Any();
Tag("Value", value);
""";
var enumerableValidator = SETestContext.CreateCS(code, $"List<object> collection").Validator;
var enumerableValidator = SETestContext.CreateCS(code, $"List<int> collection").Validator;
var collectionSymbol = enumerableValidator.Symbol("collection");
var valueSymbol = enumerableValidator.Symbol("value");
enumerableValidator.TagStates("Value").Should().HaveCount(1)
Expand All @@ -1063,10 +1063,10 @@ public void Invocation_BoolCollectionMethod_Parameters_CollectionEmpty()
{
var code = """
collection.Clear();
var value = collection.Any(x => x is { });
var value = collection.Any(x => x is 1);
Tag("Value", value);
""";
var enumerableValidator = SETestContext.CreateCS(code, $"List<object> collection").Validator;
var enumerableValidator = SETestContext.CreateCS(code, $"List<int> collection").Validator;
var collectionSymbol = enumerableValidator.Symbol("collection");
var valueSymbol = enumerableValidator.Symbol("value");
enumerableValidator.TagStates("Value").Should().HaveCount(1)
Expand All @@ -1077,16 +1077,16 @@ public void Invocation_BoolCollectionMethod_Parameters_CollectionEmpty()
public void Invocation_BoolCollectionMethod_Parameters_CollectionNotEmpty()
{
var code = """
collection.Add(new object());
var value = collection.Any(x => x is { });
collection.Add(1);
var value = collection.Any(x => x is 1);
Tag("Value", value);
""";
var enumerableValidator = SETestContext.CreateCS(code, $"List<object> collection").Validator;
var enumerableValidator = SETestContext.CreateCS(code, $"List<int> collection").Validator;
var collectionSymbol = enumerableValidator.Symbol("collection");
var valueSymbol = enumerableValidator.Symbol("value");
enumerableValidator.TagStates("Value").Should().HaveCount(1)
.And.ContainSingle(x => x[collectionSymbol].HasConstraint(CollectionConstraint.Empty))
.And.NotContain(x => x[valueSymbol].Constraint<BoolConstraint>() == null);
.And.Contain(x => x[collectionSymbol].HasConstraint(CollectionConstraint.NotEmpty))
.And.NotContain(x => x[valueSymbol].HasConstraint<BoolConstraint>());
}

[DataTestMethod]
Expand Down Expand Up @@ -1131,7 +1131,7 @@ public void Invocation_Linq_VB()
Dim Query = From Item In Items Where Item IsNot Nothing
If Query.Count <> 0 Then
Dim Value = Query(0)
Tag(""Value"", Value)
Tag("Value", Value)
End If
""";
var validator = SETestContext.CreateVB(code, "Items() As Object").Validator;
Expand Down Expand Up @@ -1201,7 +1201,7 @@ public void Invocation_InformationIsNothing_KnownSymbol(string declarationSuffix
Public Sub Main(Of T, TStruct As Structure)()
Dim Value As {declarationSuffix}
Dim Result As Boolean = IsNothing(CType(DirectCast(Value, Object), Object)) ' Some conversions in the way to detect the value type
Tag(""Result"", Result)
Tag("Result", Result)
End Sub
""";
var validator = SETestContext.CreateVBMethod(code).Validator;
Expand All @@ -1218,7 +1218,7 @@ public void Invocation_InformationIsNothing_UnknownSymbol(string type)
var code = $"""
Public Sub Main(Of TClass As Class)(Arg As {type})
Dim Result As Boolean = IsNothing(Arg)
Tag(""Result"", Result)
Tag("Result", Result)
End Sub
""";
var validator = SETestContext.CreateVBMethod(code).Validator;
Expand Down Expand Up @@ -1476,7 +1476,7 @@ public void Invocation_ObjectEquals_DoesNotLearnResult(string left, string right
object left = {left};
object right = {right};
var result = object.Equals(left, right);
Tag(""Result"", result);
Tag("Result", result);
""";
var validator = SETestContext.CreateCS(code).Validator;
validator.TagValue("Result").Should().HaveOnlyConstraint(ObjectConstraint.NotNull);
Expand Down

0 comments on commit a79e9b0

Please sign in to comment.