-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix Inline temporary variable adds unnecessary cast #70423
fix Inline temporary variable adds unnecessary cast #70423
Conversation
remove unused using
@@ -414,7 +414,7 @@ ExpressionSyntax CreateExpressionToInline() | |||
|
|||
return SyntaxFactory.ArrayCreationExpression(arrayType, arrayInitializer); | |||
} | |||
else if (isVar && expression is ObjectCreationExpressionSyntax or ArrayCreationExpressionSyntax or CastExpressionSyntax) | |||
else if (isVar && expression is ObjectCreationExpressionSyntax or ArrayCreationExpressionSyntax or CastExpressionSyntax or InvocationExpressionSyntax) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is most likely not the right fix unfortunatelly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so what you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree with DoctorKrolic. thsi cahnge doesn't really make sense. the comment below this explains the rational for why we don't need to add the cast. however, for an invocatino expression we still do need to cast to preserve semantics in many cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CyrusNajmabadi can i have an example when we need to do the cast on InvocationExpressionSyntax ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, i think i missed that this iwas the is var
case. In that case, it's likely safe to whitelist invocations as well. Can you update the comment inside to make this clearer? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@@ -22,7 +22,6 @@ | |||
using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics; | |||
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; | |||
using Microsoft.CodeAnalysis.Host; | |||
using Microsoft.CodeAnalysis.Remote; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
add comment
{ | ||
// if we have an InvocationExpressionSyntax `var x = Math.Round(1.1D);` there's no need to do any casting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs an explanation why this is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that clear ?
add explication
...s/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
…InlineTemporaryCodeRefactoringProvider.cs
Thanks! |
i don't know which tests are failing |
…y_variable_adds_unnecessary_cast
Thanks! |
trying to fix Inline temporary variable adds unnecessary cast
Fixes: #69869