Skip to content

Commit

Permalink
Remove extra logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Oct 22, 2024
1 parent 1d4289e commit 9992998
Showing 1 changed file with 3 additions and 49 deletions.
52 changes: 3 additions & 49 deletions src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2352,12 +2352,11 @@ public sealed override void Filter(
trueBuilder.Add(oneTrue);
falseBuilder.Add(oneFalse);

// TODO2
if (i > 0
&& oneTrue is False
&& this is OrSequence { RemainingTests: [Not { Negated: var negated }, ..] }
&& isTestPartOfNegated(test, negated))
&& this is OrSequence { RemainingTests: [Not, ..] })
{
// We report a warning based on heuristic to catch a common mistake (`not ... or <redundant>` pattern)
diagnostics.Add(ErrorCode.WRN_RedundantPattern, getSyntax(other));
}
}
Expand All @@ -2367,37 +2366,6 @@ public sealed override void Filter(

return;

static bool isTestPartOfNegated(BoundDagTest test, Tests negated)
{
// If we have something like `not A or ... or B` where the A test being true implies that the B test is false,
// so the B test could only be true when the `not A` test is true,
// then the user probably made a mistake having the `or B` condition
// Also handles `not "literal" or ...`
if (isTypeTest(negated, out var nonNullTest2, out var typeATest)
&& test == typeATest)
{
return true;
}

// If we have something like `not null or ... or C`,
// the C test could only be true when the `not null` test is true,
// then the user probably made a mistake having the `or C` condition
if (negated is One { Test: BoundDagExplicitNullTest { Input: var nonNullTestInput } nonNullTest }
&& test == nonNullTest)
{
return true;
}

// Handle `not 42 or ...`
if (negated is One { Test: BoundDagValueTest { Input: var valueTestInput } valueTest }
&& test == valueTest)
{
return true;
}

return false;
}

static SyntaxNode getSyntax(Tests tests)
{
return tests switch
Expand All @@ -2408,22 +2376,8 @@ static SyntaxNode getSyntax(Tests tests)
_ => throw ExceptionUtilities.UnexpectedValue(tests),
};
}

static bool isTypeTest(Tests tests, out BoundDagNonNullTest nonNullTest, /*[NotNullWhen(true)] */out BoundDagTypeTest? typeTest) // TODO2
{
if (tests is AndSequence { RemainingTests: [One { Test: BoundDagNonNullTest nonNullTest2 }, One { Test: BoundDagTypeTest typeTest2 }, ..] }
&& nonNullTest2.Input == typeTest2.Input)
{
nonNullTest = nonNullTest2;
typeTest = typeTest2;
return true;
}

nonNullTest = null;
typeTest = null;
return false;
}
}

public sealed override Tests RemoveEvaluation(BoundDagEvaluation e)
{
var builder = ArrayBuilder<Tests>.GetInstance(RemainingTests.Length);
Expand Down

0 comments on commit 9992998

Please sign in to comment.