Skip to content

Fix null check in S.Diagnostics.Contract regressed by nullability annotations - #41382

Merged
krwq merged 2 commits into
dotnet:masterfrom
krwq:nullability-compiler-bug-regression-contracts
Aug 27, 2020
Merged

Fix null check in S.Diagnostics.Contract regressed by nullability annotations#41382
krwq merged 2 commits into
dotnet:masterfrom
krwq:nullability-compiler-bug-regression-contracts

Conversation

@krwq

@krwqkrwq commented Aug 26, 2020

Copy link
Copy Markdown
Member

@krwq

krwq commented Aug 26, 2020

Copy link
Copy Markdown
MemberAuthor

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

@krwq
krwqforce-pushed the nullability-compiler-bug-regression-contracts branch from 5fa6bde to 2482f61CompareAugust 26, 2020 09:27
{
Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType!.Assembly;
MethodBase stackMethod = stack.GetFrame(i)!.GetMethod();
Assembly? caller = (stackMethod != null) ? stackMethod.DeclaringType!.Assembly : null;

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.

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
Copy Markdown
MemberAuthor

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
Copy Markdown
Member

a product bug which luckily got caught by tests

What are the tests that caught this?

@krwq

krwq commented Aug 27, 2020

Copy link
Copy Markdown
MemberAuthor

@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:masterAug 27, 2020
@carlossanlop

Copy link
Copy Markdown
Contributor

/backport to release/5.0

@github-actions

Copy link
Copy Markdown
Contributor

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

@ghostghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@krwq@jkotas@carlossanlop@Dotnet-GitSync-Bot