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

Fixing VS Crash on invalid "MemberNotNull" #45563

Merged
merged 9 commits into from
Jul 2, 2020

Conversation

kevinsun-dev
Copy link
Contributor

Fixes issue #44049.

Changelog:

  • Adds null check for NullPointerException situation
  • Adds corresponding test

@kevinsun-dev kevinsun-dev marked this pull request as ready for review June 30, 2020 19:57
@kevinsun-dev kevinsun-dev requested a review from a team as a code owner June 30, 2020 19:57
@@ -120,6 +120,7 @@ protected virtual int GetOrCreateSlot(Symbol symbol, int containingSlot = 0, boo
{
Debug.Assert(containingSlot >= 0);

if (symbol is null) return -1;
Copy link
Member

@cston cston Jun 30, 2020

Choose a reason for hiding this comment

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

if (symbol is null) return -1 [](start = 12, length = 29)

Can we check for symbol is null in the caller? It feels like we might be hiding a bug if we allow null here. #Resolved

Copy link
Member

@cston cston Jun 30, 2020

Choose a reason for hiding this comment

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

Consider adding #nullable enable ... #nullable restore around this method and the override in NullableWalker to catch cases where symbol may be null.

Then it seems reasonable to check symbol is null here as well, for robustness, but it would force callers to consider null values as well.


In reply to: 447947315 [](ancestors = 447947315)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, putting the check here doesn't seem like the right solution to me. We shouldn't be attempting to get a slot for a non-existant symbol.


In reply to: 447954354 [](ancestors = 447954354,447947315)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved a check to the correct location, added an Assert here. (Commit 8).


In reply to: 447962405 [](ancestors = 447962405,447954354,447947315)

@@ -9089,6 +9089,45 @@ public class C2
Diagnostic(ErrorCode.ERR_BadAttributeArgument, "C.M(null)").WithLocation(20, 6));
}

[Fact]
[WorkItem(44049, "https://github.com/dotnet/roslyn/issues/44049")]
public void MemberNotNullAnnotationCrashes()
Copy link
Member

@cston cston Jun 30, 2020

Choose a reason for hiding this comment

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

MemberNotNullAnnotationCrashes [](start = 20, length = 30)

Consider moving to NullableReferenceTypesTests.cs since most (all?) of the [MemberNotNull] tests are there.

Also, consider renaming since the test since the test should not crash. Perhaps something like MemberNotNull_InstanceMemberOnStaticMethod. #Resolved

@@ -1268,14 +1268,16 @@ static MethodSymbol getTopLevelMethod(MethodSymbol method)
}
}

#nullable enable
protected override int GetOrCreateSlot(Symbol symbol, int containingSlot = 0, bool forceSlotEvenIfEmpty = false)
Copy link
Contributor

@RikkiGibson RikkiGibson Jun 30, 2020

Choose a reason for hiding this comment

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

If it's possible for symbol to be null then the type should change to Symbol?. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't be possible, added an Assert to make sure in Commit 8.


In reply to: 447978511 [](ancestors = 447978511)

protected override int GetOrCreateSlot(Symbol symbol, int containingSlot = 0, bool forceSlotEvenIfEmpty = false)
{

if (containingSlot > 0 && !IsSlotMember(containingSlot, symbol))
if ((containingSlot > 0 && !IsSlotMember(containingSlot, symbol)) || symbol is null)
Copy link
Member

@cston cston Jun 30, 2020

Choose a reason for hiding this comment

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

|| symbol is null [](start = 78, length = 17)

We should check symbol is null higher in the callstack where we know what the symbol represents in the codepath for the bug repro. (Sorry, I didn't realize the caller of the base method was the override when I suggested moving the check previously.) #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the check to the place where the null object is in Commit 8.


In reply to: 447985704 [](ancestors = 447985704)

@kevinsun-dev kevinsun-dev added Area-Compilers Bug New Language Feature - Nullable Reference Types Nullable Reference Types Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner. and removed Bug labels Jul 1, 2020
@kevinsun-dev kevinsun-dev added this to the 16.8 milestone Jul 1, 2020
@kevinsun-dev kevinsun-dev self-assigned this Jul 1, 2020
@kevinsun-dev kevinsun-dev requested a review from 333fred July 1, 2020 20:08
@@ -715,6 +715,10 @@ int getSlotForFieldOrProperty(Symbol member)

if (!isStatic)
{
if (MethodThisParameter is null)
Copy link
Member

@333fred 333fred Jul 1, 2020

Choose a reason for hiding this comment

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

What is the Kind of the member in this scenario? #Closed

if (MethodThisParameter is null)
{
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: newline

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM (commit 9), one minor formatting comment.

@kevinsun-dev kevinsun-dev merged commit be56bf4 into dotnet:master Jul 2, 2020
@ghost ghost modified the milestones: 16.8, Next Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Language Feature - Nullable Reference Types Nullable Reference Types Tenet-Reliability Customer telemetry indicates that the product is failing in a crash/hang/dataloss manner.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants