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

Use [NotNullWhenFalse] and [EnsuresNotNull] to drive nullability analysis #26656

Merged
merged 18 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5357,6 +5357,12 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_ExplicitNullableAttribute" xml:space="preserve">
<value>Explicit application of 'System.Runtime.CompilerServices.NullableAttribute' is not allowed.</value>
</data>
<data name="ERR_AttributeRequiresBoolReturn" xml:space="preserve">
<value>The '{0}' attribute is only applicable on members that return a boolean type.</value>
</data>
<data name="ERR_AttributeNotApplicableOnValueType" xml:space="preserve">
<value>The '{0}' attribute is not applicable on a value type.</value>
</data>
<data name="ERR_NotNullableOperatorNotReferenceType" xml:space="preserve">
<value>The ! operator can only be applied to reference types.</value>
</data>
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,8 @@ internal enum ErrorCode
ERR_NotNullableOperatorNotReferenceType = 8624,
WRN_NullAsNonNullable = 8625,
WRN_NoBestNullabilityConditionalExpression = 8626,
ERR_AttributeRequiresBoolReturn = 8627,
Copy link
Member

Choose a reason for hiding this comment

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

ERR_AttributeRequiresBoolReturn [](start = 8, length = 31)

I didn't notice where these are used, but I'm not confident it is a good idea to have diagnostics such as this.

Copy link
Member

Choose a reason for hiding this comment

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

Because of "forward compatibility" scenarios. (Code that compiles with older compilers will fail to compile with newer compilers)


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

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the clarification.
Filed #26783 to track compat concern.

ERR_AttributeNotApplicableOnValueType = 8628,
}
// Note: you will need to re-generate compiler code after adding warnings (build\scripts\generate-compiler-code.cmd)
}
11 changes: 10 additions & 1 deletion src/Compilers/CSharp/Portable/FlowAnalysis/DataFlowPassBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,16 @@ protected int GetOrCreateSlot(Symbol symbol, int containingSlot = 0)
variableBySlot[slot] = identifier;
}

Normalize(ref this.State);
if (IsConditionalState)
{
Normalize(ref this.StateWhenTrue);
Normalize(ref this.StateWhenFalse);
}
else
{
Normalize(ref this.State);
}

return slot;
}

Expand Down
Loading