Skip to content

Don't simplify Nullable{T} to T? inside crefs#1996

Merged
shyamnamboodiripad merged 1 commit intodotnet:masterfrom
shyamnamboodiripad:DontSimplifyNullableInDocComment
Apr 23, 2015
Merged

Don't simplify Nullable{T} to T? inside crefs#1996
shyamnamboodiripad merged 1 commit intodotnet:masterfrom
shyamnamboodiripad:DontSimplifyNullableInDocComment

Conversation

@shyamnamboodiripad
Copy link
Contributor

Fixes #29

@shyamnamboodiripad
Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

💡 This comment is misleading. The ? syntax is supported in crefs, as long as you are referencing a constructed generic type. For example, the following works fine:

<see cref="Enumerable.Sum(IEnumerable{decimal?})"/>

The problem with <see cref="Nullable{T}"/> is you are actually referencing an open generic type. This is exactly the same situation as not being able to use the shorthand syntax for typeof(Nullable<>) (which also references the open generic type).

@jmarolf
Copy link
Contributor

jmarolf commented Apr 16, 2015

👍

@sharwell
Copy link
Contributor

❗ This change will cause the editor to stop trying to simplify this:

<see cref="Enumerable.Sum(IEnumerable{Nullable<decimal>})"/>

To this:

<see cref="Enumerable.Sum(IEnumerable{decimal?})"/>

We do want to support this simplification. Rather than simply use InsideCrefReference, you should use the set of conditions shown here to identify cases where Nullable{T} can't be simplified.

@shyamnamboodiripad
Copy link
Contributor Author

@sharwell thanks much for your comments and pointers above. In my original testing of this issue, I incorrectly assumed that the ? syntax is not supported inside crefs at all - but I understand the issue better now. I will look into how you solved this for the style cop analyzers above and update this PR accordingly. Thanks! 👍

@shyamnamboodiripad
Copy link
Contributor Author

@sharwell looking at the code you linked above, it seems like the checks you have are purely syntactic. In the case of the simplifier, we have access to semantic information which would allow us to check whether or not the nullable type we are trying to simplify is a constructed generic type and offer the simplification only if it is.

In other words, we can check the ITypeSymbol.DeclaringSyntaxReferences of XYZ in <see cref="Nullable{XYZ}"> to see whether XYZ is being declared inside the same cref. If yes, we are in an unconstructed generic type and we won't offer the simplification. If not (e.g., <see cref="SomeType.SomeMethod(Nullable{XYZ})"/>) we will offer the simplification.

Do you see any issues with this approach?

Also including @amcasey to see if he has an opinion.

@shyamnamboodiripad shyamnamboodiripad force-pushed the DontSimplifyNullableInDocComment branch from ac95e0a to 327d259 Compare April 23, 2015 07:48
@shyamnamboodiripad
Copy link
Contributor Author

Updated commit addresses issues raised above. I ran into some issues on compiler side while trying this fix this - I've logged #2170, #2189, #2196 and #2197 for these issues.

@srivatsn @tmeschter @mavasani @heejaechang could you please take a look?

@tmeschter
Copy link
Contributor

👍

@sharwell
Copy link
Contributor

@shyamnamboodiripad Sounds like we make the right decision going with the syntax approach. 😄 But I'm glad to see these fixed.

@shyamnamboodiripad
Copy link
Contributor Author

😊 Yes. In C# it is at least possible to use a semantics based approach. But VB currently needs to check syntax because of the above bugs.

I think it should always be possible to use semantics for type checking in any context in the languages and SemanticModel should ideally never disagree with compiler like in the above bugs. So in some ways, although that ended up delaying this fix, its good that we found these bugs 😊

@shyamnamboodiripad
Copy link
Contributor Author

@srivatsn @heejaechang - I need one more thumbs up to merge this PR. Could you please take a quick look?

@srivatsn
Copy link
Contributor

👍

shyamnamboodiripad added a commit that referenced this pull request Apr 23, 2015
…InDocComment

Correctly handle simplification of Nullable{T} to T? inside crefs 

Fixes #29
@shyamnamboodiripad shyamnamboodiripad merged commit 7e345e7 into dotnet:master Apr 23, 2015
@shyamnamboodiripad shyamnamboodiripad deleted the DontSimplifyNullableInDocComment branch April 23, 2015 21:17
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.

Incorrect simplification of Nullable{T} in XML comment

6 participants