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 null check in S.Diagnostics.Contract regressed by nullability annotations #41382

Merged

Conversation

krwq
Copy link
Member

@krwq krwq commented Aug 26, 2020

@krwq
Copy link
Member Author

krwq commented Aug 26, 2020

@danmosemsft this one has a bit smaller scope I think but it does affect Code Contracts (is anyone even using it still?)

@krwq krwq force-pushed the nullability-compiler-bug-regression-contracts branch from 5fa6bde to 2482f61 Compare August 26, 2020 09:27
@@ -628,7 +628,8 @@ private static void AssertMustUseRewriter(ContractFailureKind kind, string contr
Assembly? probablyNotRewritten = null;
for (int i = 0; i < stack.FrameCount; i++)
{
Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType!.Assembly;
MethodBase stackMethod = stack.GetFrame(i)!.GetMethod();
Assembly? caller = (stackMethod != null) ? stackMethod.DeclaringType!.Assembly : null;
Copy link
Member

Choose a reason for hiding this comment

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

DeclaringType can be null. I do not think there is anything guaranteeing that it will be non-null here. This is one of those cases nullable annotations caught a real bug.

Should the fix be to just change ! after DeclaringType to ?? No need to split it into multiple lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

We try to avoid any product changes during nullability annotations as those are always risky and can get lost in a large PR. In this case since PR is only affecting this specific change so I think we should fix it.

@jkotas
Copy link
Member

jkotas commented Aug 27, 2020

a product bug which luckily got caught by tests

What are the tests that caught this?

@krwq
Copy link
Member Author

krwq commented Aug 27, 2020

@jkotas the test was related to #41261 not to this issue. The investigation related to the failure led to finding this issue.

@krwq krwq merged commit 2337a35 into dotnet:master Aug 27, 2020
@carlossanlop
Copy link
Member

/backport to release/5.0

@github-actions
Copy link
Contributor

Started backporting to release/5.0: https://github.com/dotnet/runtime/actions/runs/227480299

@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants