Skip to content

Support basic cases in UseRangeOperator#45693

Merged
CyrusNajmabadi merged 4 commits intodotnet:masterfrom
mahalex:use-range-operator-basic-cases
Jul 7, 2020
Merged

Support basic cases in UseRangeOperator#45693
CyrusNajmabadi merged 4 commits intodotnet:masterfrom
mahalex:use-range-operator-basic-cases

Conversation

@mahalex
Copy link
Contributor

@mahalex mahalex commented Jul 6, 2020

Fixes #45637

return false;
}

if (_methodToMemberInfo.TryGetValue(method, out memberInfo))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (_methodToMemberInfo.TryGetValue(method, out memberInfo))
if (!_methodToMemberInfo.TryGetValue(method, out memberInfo))

then have hte logic to try to produce the value in the if-statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

/// <summary>
/// Can be null, if we are dealing with one-argument call to a slice-like method.
/// </summary>
public readonly IOperation Op2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public readonly IOperation Op2;
public readonly IOperation? Op2;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

var targetMethod = invocation.TargetMethod;

// Try to see if we're calling into some sort of Slice method with a matching
// indexer or overload
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not finding tehse comments helpful. having real world examples of the before/after would be more helpful here imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I re-worded the comment.

targetMethod,
memberInfo,
startOperation,
null); // secondOperation is null: the range will run to the end.
Copy link
Contributor

Choose a reason for hiding this comment

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

named param.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

null); // secondOperation is null: the range will run to the end.
}

private static Result? AnalyzeInvocationWithTwoArguments(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static Result? AnalyzeInvocationWithTwoArguments(
private static Result? AnalyzeTwoArgumentInvocation(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also renamed AnalyzeInvocationWithOneArgument to AnalyzeOneArgumentInvocation.

// From: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/ranges.md#decisions-made-during-implementation
//
// When looking for the pattern members, we look for original definitions, not
// constructed members
Copy link
Contributor

Choose a reason for hiding this comment

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

just make this a normal method. breaking up an expression with complex comments like this just makes things too hard to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

// of the range. i.e. `start..`
if (IsInstanceLengthCheck(lengthLikeProperty, instance, endOperation))
var endFromEnd = false;
ExpressionSyntax endExpr;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just make this null, and then just set it in the case where we have it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

var overloadWithTwoArguments = method.ContainingType
.GetMembers(method.Name)
.OfType<IMethodSymbol>()
.FirstOrDefault(s => IsSliceLikeMethod(s));
Copy link
Contributor

Choose a reason for hiding this comment

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

should we rename IsSliceLikeMethod to IsTwoArgumentSliceLikeMethod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed; also renamed IsSliceLikeMethodWithOneArgument to IsOneArgumentSliceLikeMethod.

@CyrusNajmabadi
Copy link
Contributor

Nice start!

Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

Awesome. Thanks much!

@CyrusNajmabadi
Copy link
Contributor

Feel free to ping me when this passes, and i'll merge in. Thanks!

@mahalex
Copy link
Contributor Author

mahalex commented Jul 6, 2020

@CyrusNajmabadi thanks for the feedback! It’s ready for merging now.

@CyrusNajmabadi
Copy link
Contributor

Thank you for the contribution!

@CyrusNajmabadi CyrusNajmabadi merged commit 81d4452 into dotnet:master Jul 7, 2020
@ghost ghost added this to the Next milestone Jul 7, 2020
@jinujoseph jinujoseph added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Jul 7, 2020
@davkean
Copy link
Member

davkean commented Jul 7, 2020

@mahalex Nice!

@JoeRobich JoeRobich modified the milestones: Next, 16.8.P1 Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Substring can be simplified" misses basic cases

5 participants