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

Add string ctor to MemberNotNull/When #42712

Merged
merged 2 commits into from
Mar 26, 2020
Merged

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Mar 24, 2020

Follow-up on PR #41675 (Add support for MemberNotNull/When attributes)

The constructors with string[] are not CLS-compliant and that causes problems for the BCL team. From email discussion with LDM, we'll add simple constructors that take a single member name at a time, and we'll allow the attributes to be instantiated multiple times.

Relates to #41438 (Implement MemberNotNull nullability attribute)
Corresponding BCL change: dotnet/runtime#33864

@jcouv jcouv added this to the 16.6.P3 milestone Mar 24, 2020
@jcouv jcouv self-assigned this Mar 24, 2020
{
if (targetSignature[signatureByteIndex - 1] != (byte)SignatureTypeCode.SZArray)
{
return false;
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 there was a bug here. This method could not distinguish properly between the string case and the string[] case. To tighten that logic, I had to refactor a bit (extract a local function).

@jcouv jcouv marked this pull request as ready for review March 24, 2020 05:36
@jcouv jcouv requested a review from a team as a code owner March 24, 2020 05:36
{
var memberName = member.DecodeValue<string>(SpecialType.System_String);
string? memberName = value.DecodeValue<string>(SpecialType.System_String);
Copy link
Member

Choose a reason for hiding this comment

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

Won't this throw in the case where the customer uses a version of MemberNotNull where there is a ctor with a non-string argument? I'm unsure what our tolerance here is for malformed attributes. Know @RikkiGibson is hitting this with the obsolete change.

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 should get here in such case. This method is only called once we've found the attribute we're interested in by AttributeDescription (which verifies one of two signatures we want was matched)

{
return null;
if (TryExtractStringValueFromAttribute(ai.Handle, out var extracted))
Copy link
Member

Choose a reason for hiding this comment

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

var [](start = 74, length = 3)

Please be explicit here: string

var result = ArrayBuilder<string>.GetInstance(attrInfos.Count);

foreach (var ai in attrInfos)
else if (TryExtractStringArrayValueFromAttribute(ai.Handle, out var extracted2))
Copy link
Member

@gafter gafter Mar 25, 2020

Choose a reason for hiding this comment

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

var [](start = 80, length = 3)

Same here string[], and two places in the next method.

Diagnostic(ErrorCode.WRN_MemberNotNullWhen, "true").WithArguments("field2", "True").WithLocation(29, 16),
// (29,16): warning CS8775: Member 'field3' may not have a null value when exiting with `True`.
// get => true;
Diagnostic(ErrorCode.WRN_MemberNotNullWhen, "true").WithArguments("field3", "True").WithLocation(29, 16)
);
}
Copy link
Member

Choose a reason for hiding this comment

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

} [](start = 8, length = 1)

Please add a test (if there isn't one already) with multiple applications of the params version of MemberNotNull.

Please add a test with [MemberNotNull(member: null)] and [MemberNotNull(members: null)] including repetitions.

Similarly for MemberNotNullWhen.

@gafter
Copy link
Member

gafter commented Mar 25, 2020

Looks good (Iteration 1) but please add a couple of tests as noted.

Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

:shipit:

@jcouv jcouv requested a review from a team as a code owner March 25, 2020 23:00
Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

Perfect, thanks!

@jcouv jcouv merged commit 9e03a9a into dotnet:master Mar 26, 2020
@ghost ghost modified the milestones: 16.6.P3, Next Mar 26, 2020
@jcouv jcouv deleted the member-notnull branch March 26, 2020 00:46
333fred added a commit to 333fred/roslyn that referenced this pull request Mar 26, 2020
* upstream/master: (697 commits)
  Update comment for clarity
  More solution API tests (dotnet#42451)
  Task queue refactoring (dotnet#42610)
  Add string ctor to MemberNotNull/When (dotnet#42712)
  Use the same block structure for code and Metadata As Source
  Add work items
  When generating abstract members, generate them as protected, not internal
  Avoid operations on disposed workspace (dotnet#42768)
  Remove duplicate validation logic
  Speed up regex comment detector pattern.
  Stop walking up once we hit a statement
  Speed up regex comment detector pattern.
  Strengthen the condition in which nodes are determined to be in the same block
  Remove the SolutionPopulator incremental analyzer.
  Update Visualizer version again to fix bug, actually use invariant culture.
  Formatting: force a space after attribute on parameter (dotnet#42466)
  Add test for different case VB
  Update src/EditorFeatures/VisualBasicTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.vb
  Update src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs
  GenerateUniqueName for ReplaceMethodWithProperty
  ...
@sharwell sharwell modified the milestones: Next, temp, 16.6.P3 Apr 6, 2020
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.

4 participants