Skip to content

Commit

Permalink
Revert "unlearn constraints"
Browse files Browse the repository at this point in the history
This reverts commit cba9ba8.
  • Loading branch information
mary-georgiou-sonarsource committed Jul 3, 2024
1 parent 1cf8a40 commit 718a236
Show file tree
Hide file tree
Showing 2 changed files with 2,147 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ internal static class CollectionTracker
nameof(Stack<int>.Pop)
];

private static readonly HashSet<string> ElementExistenceMethods =
[
nameof(Enumerable.Contains),
nameof(Enumerable.Any),
nameof(List<int>.Exists)
];

private static readonly HashSet<string> AddOrRemoveMethods = [.. AddMethods, .. RemoveMethods];

public static ProgramState LearnFrom(ProgramState state, IObjectCreationOperationWrapper operation)
Expand Down Expand Up @@ -156,19 +149,15 @@ public static ProgramState LearnFrom(ProgramState state, IInvocationOperationWra
{
return state.SetOperationConstraint(invocation, constraint);
}

var instance = invocation.TargetMethod.IsExtensionMethod && !invocation.Arguments.IsEmpty
? state.ResolveCaptureAndUnwrapConversion(invocation.Arguments[0].ToArgument().Value)
: invocation.Instance;
if (instance is { } && instance.Type.DerivesOrImplementsAny(CollectionTypes))
if (invocation.Instance is { } instance && instance.Type.DerivesOrImplementsAny(CollectionTypes))
{
var targetMethod = invocation.TargetMethod;
var symbolValue = state[instance] ?? SymbolicValue.Empty;
if (AddMethods.Contains(targetMethod.Name))
{
return SetOperationAndSymbolValue(symbolValue.WithConstraint(CollectionConstraint.NotEmpty));
}
else if (RemoveMethods.Contains(targetMethod.Name) || ElementExistenceMethods.Contains(targetMethod.Name))
else if (RemoveMethods.Contains(targetMethod.Name))
{
return SetOperationAndSymbolValue(symbolValue.WithoutConstraint(CollectionConstraint.NotEmpty));
}
Expand Down
Loading

0 comments on commit 718a236

Please sign in to comment.