Skip to content

Fix issues with 'Remove unnecessary cast'#42883

Merged
22 commits merged intodotnet:masterfrom
CyrusNajmabadi:unnecessaryCAst
Mar 30, 2020
Merged

Fix issues with 'Remove unnecessary cast'#42883
22 commits merged intodotnet:masterfrom
CyrusNajmabadi:unnecessaryCAst

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Mar 29, 2020

Fixes #41433
Fixes #38599
Fixes #32491
Fixes #25021
Fixes #2987
Fixes #38347
Fixes #36631
Fixes #34326
Fixes #29726
Fixes #6309
Fixes #34873
Fixes #37953
Fixes #42657
Fixes #42108

This PR should be reviewed one commit at a time.

@CyrusNajmabadi CyrusNajmabadi requested a review from mavasani March 29, 2020 22:55
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Linq;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

stale file. likely a merge conflict when we moved things to the shared layer.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review March 29, 2020 23:48
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner March 29, 2020 23:48
return false;

// Don't remove any explicit numeric casts.
// https://github.com/dotnet/roslyn/issues/2987 tracks improving on this conservative approach.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❔ Comment still necessary?

Comment on lines +161 to +163
if (castedExpressionNode.WalkDownParentheses().IsKind(SyntaxKind.DefaultLiteralExpression) &&
!castType.Equals(outerType) &&
outerType.IsNullable())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😕 It's hard to relate this condition to the one it tests for. I'll need to come back to it.

@sharwell
Copy link
Copy Markdown
Contributor

Fixes #2987

Please update that issue to explain how this improvement was approached.

Comment on lines +450 to +451
// Switch expression's expression changed. Ensure it's the same type as before. If not, inference of
// the meaning of the patterns within can change.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❔ Do we not need to check the patterns, like we do for switch statements?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's quite possble we need to for total correctness. i'm not certain at this point. going to leave it alone for now :)

CyrusNajmabadi and others added 4 commits March 29, 2020 20:05
…mplification/Simplifiers/CastSimplifier.cs

Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
…mplification/Simplifiers/CastSimplifier.cs

Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
…mplification/Simplifiers/CastSimplifier.cs

Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
@CyrusNajmabadi CyrusNajmabadi changed the title Fix issues with 'Remove unneccessary cast' Fix issues with 'Remove unnecessary cast' Mar 30, 2020
public int Compare(object x, object y)
{
return this.x.Compare(x, y);
return ((IComparer)this.x).Compare(x, y);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📝 I'm OK with the approach taken in this pull request to put us back on a more conservative path, but we should file a follow-up issue to consider ways to improve this scenario in the future.

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Auto-approval

@jinujoseph jinujoseph added this to the 16.6.P3 milestone Mar 30, 2020
@ghost ghost merged commit fcefb5e into dotnet:master Mar 30, 2020
@CyrusNajmabadi CyrusNajmabadi deleted the unnecessaryCAst branch March 30, 2020 17:42
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment