Skip to content

NullableContextAttribute for property parameters is from accessor rather than containing type#47223

Merged
cston merged 1 commit intodotnet:masterfrom
cston:47221
Aug 29, 2020
Merged

NullableContextAttribute for property parameters is from accessor rather than containing type#47223
cston merged 1 commit intodotnet:masterfrom
cston:47221

Conversation

@cston
Copy link
Contributor

@cston cston commented Aug 28, 2020

Properties from metadata have parameters defined by the accessor including any [Nullable] attributes, so the [NullableContext] attribute should also be taken from the accessor as well.

(The [NullableContext] attribute for a method parameter, including accessors, is the nearest attribute on the method, or the containing types.)

Fixes #47221.

@cston cston requested a review from a team as a code owner August 28, 2020 05:44
@cston cston requested a review from jcouv August 28, 2020 05:44
{
var a = A.F(x, y);
var b = a[x, y];
b.ToString(); // 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, a warning was reported for y in a[x, y].

{
var a = new A();
var b = a[x, y]; // 1
b.ToString();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, no warning was reported for y in a[x, y].

@eerhardt
Copy link
Member

Will we need to take a new compiler in dotnet/runtime in the release/5.0 branch to pick this change up? That way our ref assembiles will be correct when we ship them for 5.0.

@cston
Copy link
Contributor Author

cston commented Aug 28, 2020

Will we need to take a new compiler in dotnet/runtime in the release/5.0 branch to pick this change up? That way our ref assembiles will be correct when we ship them for 5.0.

I believe the ref assemblies are already emitted correctly. The issue was in decoding the attributes when loading the methods from metadata.

public class A
{
public object this[object? x, object y] => new object();
public static A? F0;
Copy link
Member

Choose a reason for hiding this comment

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

Are F0-4 necessary for this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are F0-4 necessary for this test?

Yes, we need more annotated reference types than unannotated reference types in the type definition to generate a [NullableContext(2)] on type, and that attribute is needed to force a [NullableContext(1)] on the property accessor.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we need more annotated reference types than unannotated reference types in the type definition

that's probably why I couldn't repro this standalone myself....

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 1), other than the question about unused test elements.

@cston cston merged commit 3090d91 into dotnet:master Aug 29, 2020
@ghost ghost added this to the Next milestone Aug 29, 2020
@cston cston deleted the 47221 branch August 29, 2020 15:40
333fred added a commit to 333fred/roslyn that referenced this pull request Aug 31, 2020
* upstream/master: (43 commits)
  Fix typos (dotnet#47264)
  Disable CS0660 where Full Solution Analysis produces a different result
  Pass in correct arguments to TypeScript handler
  Add skipped failing test for IDE0044 (dotnet#45288)
  Avoid first chance exception
  Code review feedback part 3
  Update stale URLs in the readme
  Update IntegrationTestSourceGenerator.cs
  Fix comment
  Update IntegrationTestSourceGenerator.cs
  Remove unused reference to obsolete class
  Update nullable annotations in Classification folder
  Update generator public API names: (dotnet#47222)
  NullableContextAttribute for property parameters is from accessor (dotnet#47223)
  Modify global analyzer config precedence: (dotnet#45871)
  Skip the C# source generator integration test running for now
  Additional XAML LSP handlers (dotnet#47217)
  Remap diagnostics using IWorkspaceVenusSpanMappingService in-proc
  Warn on type named "record" (dotnet#47094)
  Bail out early before getting SyntaxTree
  ...
@allisonchou allisonchou modified the milestones: Next, 16.8.P3 Aug 31, 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.

Unexpected warning passing nullable argument to annotated indexer

6 participants