Add a refactoring to convert a common for-loop form to a foreach-statement.#25469
Add a refactoring to convert a common for-loop form to a foreach-statement.#25469jinujoseph merged 48 commits intodotnet:dev15.7.xfrom
Conversation
There was a problem hiding this comment.
sorry, don't know what this means. #Resolved
There was a problem hiding this comment.
could you use ?:? #Resolved
There was a problem hiding this comment.
typeNode = is duplicated in each branch #Resolved
There was a problem hiding this comment.
it feels like it would be very large and unweildy. I found this to read better. #Resolved
There was a problem hiding this comment.
we don't have a general rule of avoiding hte pattern of:
SomeVar v;
// initialize through branchign code
// use vDevs decide on a case by case basis. #Resolved
There was a problem hiding this comment.
this is nice. I should reuse this.
There was a problem hiding this comment.
i thought we weren't supposed to format this way?
There was a problem hiding this comment.
i would personally also expect this offered after ')'
|
@Neme12 This has not been submitted for review. it is a WIP (work in progress). I will let you know when it's ready :) |
|
@heejaechang I've extracted out the helper to generate a unique name token in a specific context. you can port that over if you want. |
|
VB is done. Tests coming now. @dotnet/roslyn-ide @heejaechang @Neme12 @jinujoe this is ready for review now. |
There was a problem hiding this comment.
this is a little weird. isn't there something like FirstAncestorOrSelf<> or GetAncestorOrSelf<> you could use? #Resolved
There was a problem hiding this comment.
yup. #resolved #Resolved
There was a problem hiding this comment.
in this type, considering so many methods are simply to just represent the interface signature, we don't wrap and just forward things along. I agree it's not consistent, but it helps keep this type from literally becoming 5x as long and having the signatures mask what's actually relevant.
There was a problem hiding this comment.
would a better place for this be inside NameGenerator?
There was a problem hiding this comment.
NameGenerator is designed to be Roslyn agnostic. i.e. it's literally jsut string manipulation. we've deliberately kept it that way so that partners can use it/copy it trivially.
There was a problem hiding this comment.
it's a little confusing to use 'stepValue' for both the value and the expression it's calculated from, consider adding 'expression' to the name or differentiating it in some other way #Resolved
There was a problem hiding this comment.
Sure. #Resolved
There was a problem hiding this comment.
#resolved #Resolved
There was a problem hiding this comment.
i see waht's going on here and it's not very nice, but i can't think of any way how to improve this #WontFix
There was a problem hiding this comment.
#won'tfix #Resolved
There was a problem hiding this comment.
can these move to abstract one and use IOperation rather than doing it on language specific way?
There was a problem hiding this comment.
I don't think so. Vb and C# literally uses different types here (IForToLoop vs IForLoop). So you'd have to write custom code anyways. Given that, i don't mind explicitly writing this at the language level since each language is different.
There was a problem hiding this comment.
Also, i tried out hte IOperation approach and i had to jump through lots of hoops due to conversion operations in the code. It was actually more annoying.
There was a problem hiding this comment.
can you do return TryStepGetValue?
There was a problem hiding this comment.
it makes me sad that there's no UnaryExpressionSyntax that would let us merge these cases #WontFix
There was a problem hiding this comment.
#won'tfix #Resolved
There was a problem hiding this comment.
few ideas:
- could you use pattern matching instead of the casts? for assignment you'd have to use
when .IsKind(), do you think that to be an improvement or not? - i don't like this imperative style with variables outside assigned from each case with a break everywhere, it seems like this would deserve maybe a local function or a method that could have a single return from each case with a tuple of (operand, stepValue)... in default it would return a null operand and the
operand is IdentifierNameSyntaxcheck would still work as expected... but this is all up to you, I'm just throwing some suggestions/ideas
There was a problem hiding this comment.
i'm ok with it as it is. If we had a match expression, i might consider using that. But i'm ok with things as they are here.
|
tests added. @dotnet/roslyn-ide please review at your earliest convenience. |
|
Note: one of the best things i could get from reviewers are potentially interesting cases i missed in both languages. VB can be especially surprising with all the forms it supports :) |
|
@heejaechang Can you review? (in exchange for the reviews i did :)) |
|
@jcouv Woudl appreciate your eyes here. |
|
@Pilchie This refactoring seems very safe for 15.7. Woudl you want it there, or would 15.8 make sense? |
|
I believe we want it in 15.7 as long as it's code reviewed and buddy tested in within the next week. @jinujoseph / @kuhlenh |
|
That would be great! The ball's in your court :) |
There was a problem hiding this comment.
array[i] [](start = 30, length = 8)
Consider adding a test where array[i] appears more than once in the foreach block.
Thanks! I'm going to add some more checks and warnings for potential mutations to the collection. I think that's very reasonable! |
|
@jinujoseph PR feedback addressed. this can go in once green. |
|
@dotnet/roslyn-infrastructure I'm getting a failure on the new spanish unit test build: Does anyone know what this is about? |
|
@tmeschter @jasonmalinowski do you know anything about that msbuild error? |
|
@CyrusNajmabadi That queue is still experimental, safe to ignore. |
|
oh thanks. i missed that. |
|
retest windows_debug_unit32_prtest please |
|
@Pilchie for ask mode approval |
|
@jinujoseph This has passed and can be merged in. All the failures are the current issue with "error MSB6002: The command-line for the "CreatePkgDef" task is too long." |
|
thanks @CyrusNajmabadi , this is pending approval from @Pilchie |
|
Approved - thanks @CyrusNajmabadi |
|
@333fred test failures expected ? |
|
test windows_release_vs-integration_prtest |
|
@jinujoseph It's not a test failure. The error with integration tests (as i mentioned above) is: I don't know what can be done about this. Thoughts @333fred @jasonmalinowski -- Jason, this is not the spanish queue. This is hte integration test queue. I'm not sure i feel comfortable having my stuff not go through integration testing, even if htat queue isn't required. |
|
The integration test queues are in need of the same fix as the Spanish queue. You can disregard those failures. |
|
Thanks @jasonmalinowski . @jinujoseph This can be merged in when convenient for you. |
|
Thanks all. This is going to be a great release! |
|
Agreed - so excited. |



Tagging @heejaechang .
Todo: