Skip to content
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 interpolated string refactoring to work for Console.Write* #55521

Merged
merged 4 commits into from
Aug 17, 2021

Conversation

ryzngard
Copy link
Contributor

Fixes #55053

@ryzngard ryzngard requested a review from a team as a code owner August 10, 2021 00:39
.OfType<IMethodSymbol>()
.Where(ShouldIncludeFormatMethod)
.ToImmutableArray();
var consoleType = semanticModel.Compilation.GetTypeByMetadataName(typeof(Console).FullName);
Copy link
Contributor

@jmarolf jmarolf Aug 10, 2021

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe. The intention of this PR was to open that possibility up easily without adding them, since the original issue and design only mentioned console.

Copy link
Member

Choose a reason for hiding this comment

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

AppendFormat is fun because you would want it to substitute with Append($"")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, I'm really thinking there should be some sort of abstraction here for all of that...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated included ones in this PR

.OfType<IMethodSymbol>()
.Where(ShouldIncludeFormatMethod)
.ToImmutableArray();
var consoleType = semanticModel.Compilation.GetTypeByMetadataName(typeof(Console).FullName);
Copy link
Member

Choose a reason for hiding this comment

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

AppendFormat is fun because you would want it to substitute with Append($"")

@@ -35,18 +35,22 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);

var stringType = semanticModel.Compilation.GetSpecialType(SpecialType.System_String);
if (stringType == null)

if (stringType is null)
Copy link
Member

Choose a reason for hiding this comment

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

This if condition is unreachable. Only GetTypeByMetadataName can return null. For special type if it doesn't exist, the compiler returns an error symbol.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Looks like the initial code was wrong then. Fixing

@ryzngard ryzngard merged commit 99d4b9b into dotnet:main Aug 17, 2021
@ghost ghost added this to the Next milestone Aug 17, 2021
@ryzngard ryzngard deleted the issues/55053_interpolated_string branch August 17, 2021 21:42
@dibarbet dibarbet modified the milestones: Next, 17.0.P4 Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

String interpolation refactoring doesn't work on Console.WriteLine
6 participants