Skip to content

Fixing NullReferenceException inside ConvertToInterpolatedString#25225

Merged
DustinCampbell merged 2 commits intodotnet:masterfrom
Neme12:concatToInterpolatedString
Apr 20, 2018
Merged

Fixing NullReferenceException inside ConvertToInterpolatedString#25225
DustinCampbell merged 2 commits intodotnet:masterfrom
Neme12:concatToInterpolatedString

Conversation

@Neme12
Copy link
Copy Markdown
Contributor

@Neme12 Neme12 commented Mar 5, 2018

fixes #20943

@Neme12 Neme12 requested a review from a team as a code owner March 5, 2018 12:58
@Neme12
Copy link
Copy Markdown
Contributor Author

Neme12 commented Mar 5, 2018

@dotnet-bot retest windows_release_vs-integration_prtest please

@Neme12
Copy link
Copy Markdown
Contributor Author

Neme12 commented Mar 5, 2018

Note: it's disabled because dynamic could have a custom + operator (it likely won't, but this is probably not worth investing in as most people don't use dynamic - and if they do, they already have to get used to IDE features not working).

@Neme12
Copy link
Copy Markdown
Contributor Author

Neme12 commented Mar 5, 2018

this is probably not worth investing in

A good approach might actually be to offer the refactoring but show a warning. This is only a refactoring so false positives wouldn't be an issue.

method.ContainingType.SpecialType == SpecialType.System_String &&
return semanticModel.GetSymbolInfo(expression, cancellationToken).Symbol is IMethodSymbol method &&
method.MethodKind == MethodKind.BuiltinOperator &&
method.ContainingType?.SpecialType == SpecialType.System_String &&
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.

@sharwell @jasonmalinowski This is rather interesting. We have a MethodSymbol without a null ContainingType. I'm pretty certain there will be a lot of codepaths in the IDE that will not be resilient to this sort of thing. The presumption was that fields/props/events/methods would all be contained in types (possibly the implicit script class for scripts).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ouch, that's interesting indeed. 😦 @jaredpar or maybe @jcouv do we know more when this can happen?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'll take a look, that does seem wrong.
What's the expression used in semanticModel.GetSymbolInfo in this example?

Filed #25377

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 a binary + expression involving dynamic

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.

Perhaps the compiler synthesizes methods for dynamic invocations? But then doesn't have an INamedTypeSymbol to place them on (because IDynamicTypeSymbol isn't an INamedTypeSymbol). (Just spitballing).

However, for this case, it would be nice if we could synthesize a type. Similar to how top level members in script code belong to an implicit named type representing the script class.

@jcouv jcouv added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Mar 11, 2018
@jcouv jcouv added the Area-IDE label Mar 30, 2018
Copy link
Copy Markdown
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

Thanks for contributing this fix @Neme12. I'm going to ahead and merge this, regardless of the potential for a fix on the compiler side. I agree with @CyrusNajmabadi that ContainingType shouldn't be null. If the compiler fixes it, this null-check will just become a bit paranoid.

@DustinCampbell DustinCampbell merged commit 8df7f5c into dotnet:master Apr 20, 2018
@Neme12 Neme12 deleted the concatToInterpolatedString branch April 20, 2018 14:45
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.

CSharpConvertConcatenationToInterpolatedStringRefactoringProvider encountered an error and has been disabled.

5 participants