Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup improper parenthesized expression in 'use pattern combinators'. #73391

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ private static bool IsTopmostExpression(ExpressionSyntax node)
{
return node.WalkUpParentheses().Parent switch
{
LambdaExpressionSyntax _ => true,
AssignmentExpressionSyntax _ => true,
ConditionalExpressionSyntax _ => true,
ExpressionSyntax _ => false,
LambdaExpressionSyntax => true,
AssignmentExpressionSyntax => true,
ConditionalExpressionSyntax => true,
ExpressionSyntax => false,
_ => true
};
}
Expand All @@ -142,10 +142,10 @@ private static bool IsTrivial(AnalyzedPattern pattern)
{
return pattern switch
{
Not { Pattern: Constant _ } => true,
Not { Pattern: Source { PatternSyntax: ConstantPatternSyntax _ } } => true,
Not _ => false,
Binary _ => false,
Not { Pattern: Constant } => true,
Not { Pattern: Source { PatternSyntax: ConstantPatternSyntax } } => true,
Not => false,
Binary => false,
_ => true
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static async Task<DebugDataTipInfo> GetInfoAsync(Document document, int
: default;
}

if (expression.IsAnyLiteralExpression())
if (expression is LiteralExpressionSyntax)
{
// If the user hovers over a literal, give them a DataTip for the type of the
// literal they're hovering over.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task TestMissingOnExpression(string expression)
await TestAllMissingOnExpressionAsync(expression);
}

[InlineData("i == default || i > default(int)", "i is default(int) or > (default(int))")]
[InlineData("i == default || i > default(int)", "i is default(int) or > default(int)")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the bug that was being fixed.

[InlineData("!(o is C c)", "o is not C c")]
[InlineData("o is int ii && o is long jj", "o is int ii and long jj")]
[InlineData("o is string || o is Exception", "o is string or Exception")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static bool IsTypeApparentInAssignmentExpression(
}

// literals, use var if options allow usage here.
if (initializerExpression.IsAnyLiteralExpression())
if (initializerExpression is LiteralExpressionSyntax)
{
return stylePreferences.HasFlag(UseVarPreference.ForBuiltInTypes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ private static bool AddSimpleName(SimpleNameSyntax simpleName, List<string> part
return true;
}

public static bool IsAnyLiteralExpression(this ExpressionSyntax expression)
=> expression is LiteralExpressionSyntax;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointless helper. removed as i would prefer people make the direct and clear type checks.


public static bool IsInConstantContext([NotNullWhen(true)] this ExpressionSyntax? expression)
{
if (expression == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,15 @@ public static bool CanRemoveParentheses(
// (null) -> null
// (default) -> default;
// (1) -> 1
if (expression.IsAnyLiteralExpression())
if (expression is LiteralExpressionSyntax)
return true;

// (typeof(int)) -> typeof(int)
// (default(int)) -> default(int)
// (checked(1)) -> checked(1)
// (unchecked(1)) -> unchecked(1)
// (sizeof(int)) -> sizeof(int)
if (expression is TypeOfExpressionSyntax or DefaultExpressionSyntax or CheckedExpressionSyntax or SizeOfExpressionSyntax)
return true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the fix.


// (this) -> this
Expand Down
Loading