Skip to content

Preserve trivia when simplifier removes unnecessary this / Me keywords.#1965

Merged
shyamnamboodiripad merged 1 commit intodotnet:masterfrom
shyamnamboodiripad:PreserveTriviaWhenRemovingThisQualification
Apr 21, 2015
Merged

Preserve trivia when simplifier removes unnecessary this / Me keywords.#1965
shyamnamboodiripad merged 1 commit intodotnet:masterfrom
shyamnamboodiripad:PreserveTriviaWhenRemovingThisQualification

Conversation

@shyamnamboodiripad
Copy link
Contributor

Fixes #50

@shyamnamboodiripad
Copy link
Contributor Author

@srivatsn @tmeschter @jmarolf @mavasani @heejaechang Could you please take a look?

@tmeschter
Copy link
Contributor

How general is this fix? That is, does it only apply to situations where we remove this and Me, or will it preserve trivia in all kids of simplification? For example, does it also apply in these situations:

  • Simplifying qualified type names: System.Exception -> Exception?
  • Replacing types with keywords: Int32 -> int?

@shyamnamboodiripad
Copy link
Contributor Author

@tmeschter This fix only addresses simplification of MemberAccessExpression (e.g. this.InstanceMethod()->InstanceMethod(), Type.StaticField-> StaticField) i.e. the case mentioned in #50.

But looks like we have same issue for `QualifiedNames`` too. Let me try and expand the fix to cover that case too.

@sharwell
Copy link
Contributor

This seems like it would benefit from the WithoutFormatting methods we use in StyleCopAnalyzers.

@shyamnamboodiripad
Copy link
Contributor Author

@tmeschter, I started going down the route of fixing up the QualifiedNames cases and discovered that there are several cases where we don't preserve trivia today -

  • System.\* comment *\ Int32 -> int (i.e. simplify to predefined type in both member access as well as qualified names)
  • System. \* comment *\ Int32 -> alias (i.e. simplify to alias both in both member access as well as qualified names)
  • Nullable< \*comment *\ T> -> T?
  • Preserving trivia when replacing generic names with aliases
  • Removing type arguments for generic methods
  • Simplifying alias qualified names global::System...

In the end, seeing the number of changes I had to make I concluded that it would be better to postpone the larger fix to address all these cases until later. Although this is definitely buggy behavior, I feel this is lower priority than other bugs that need to be addressed + the effort spent on testing all these changes now is probably not worth it.

When we have more time later, we should a. audit all the places that need fixing (in addition to the above list, I am also not sure whether we preserve trivia correctly in other reducers such as extension method simplification, parenthesis simplification etc. some of which can only be invoked via API) and b. test all the changes properly.

I plan to check in the changes in this PR to address the one case mentioned in the above bug. I will log a separate issue to revisit this code to fix up remaining cases above.

@srivatsn
Copy link
Contributor

👍

shyamnamboodiripad added a commit that referenced this pull request Apr 21, 2015
…movingThisQualification

Preserve trivia when simplifier removes unnecessary this / Me keywords.

Fixes #50
@shyamnamboodiripad shyamnamboodiripad merged commit ce1fa33 into dotnet:master Apr 21, 2015
@shyamnamboodiripad shyamnamboodiripad deleted the PreserveTriviaWhenRemovingThisQualification branch April 21, 2015 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplifier removes trivia when eliminating 'this.' uses.

5 participants